开发者

Silverlight HeaderedContentControl.Header Focus Problem

I have a button in my Header of the HeaderedContentControl When i click on the button the command fires properly, but because the actual listboxitem isnt selected I have no data to work with. How do I cause the HeaderedContentControl be selected when a child control is selected or interacted with first?

Here is my control

<ListBox  x:Name="SearchList"
                      Grid.Row="1"
                      Grid.Column="0"
                      Background="Transparent"
                      BorderThickness="0"
                      ItemsSource="{Binding Path=SearchResults}"
                      SelectedItem="{Binding Path=SelectedResult,Mode=TwoWay,Converter={StaticResource DebugConverter}}"
                      HorizontalContentAlignment="Stretch"
                      HorizontalAlignment="Stretch"
                      ScrollViewer.VerticalScrollBarVisibility="Visible" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Width="600"
                                Margin="20,2,0,0"
                                Style="{StaticResource BorderStyle}">
                            <sb:BindingHelper.Binding>
                                <sb:BindingList>
                                    <sb:RelativeSourceBinding TargetProperty="Background"
                                                              RelativeMode="FindAncestor"
                                                              AncestorType="ListBoxItem"
                                                              Converter="{StaticResource DebugConverter}"
                                                              ConverterParameter="AlternatingRows" />
                                </sb:BindingList>
                            </sb:BindingHelper.Binding>
                            <toolkit:HeaderedContentControl IsTabStop="True">
                                <toolkit:HeaderedContentControl.Header>
                                    <Grid Width="575"
                                          Margin="5,5,10,0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="100" />
                                            <ColumnDefinition Width="100" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <TextBlock Grid.Column="0"
                                                   Grid.Row="0"
                                                   Text="{Binding Path=PatientName}"
                                                   HorizontalAlignment="Left"
                                                   Margin="0" />
                                        <Button Grid.Column="3"
                                                Grid.Row="0"
                                                Content="Complete Survey"
                                                IsTabStop="False">
                                            <sb:BindingHelper.Binding>
                                                <sb:BindingList>
                                                    <sb:RelativeSourceBinding Path="DataContext.OpenSurveyCommand"
                                                                              TargetProperty="Command"
                                                                              RelativeMode="FindAncestor"
                                                                              AncestorType="ListBox"
                                                                              Converter="{StaticResource DebugConverter}"
                                                                              ConverterParameter="SurveyCommandButton" />
                                                    <sb:RelativeSourceBinding Path="DataContext.HasFocus"
                                                                              TargetProperty="Focus" />

                                                </sb:BindingList>
                                            </sb:BindingHelper.Binding>
                                        </Button>
                                    </Grid>
                                </toolkit:HeaderedContentControl.Header>
                                <sb:BindingHelper.Binding>
                                    <sb:RelativeSourceBinding TargetProperty="IsExpanded"
                                                              Path="IsSelected"
                                                              RelativeMode="FindAncestor"
                                                              AncestorType="ListBoxItem"
                                                              BindingMode="TwoWay" />
                                </sb:BindingHelper.Binding>
                                <Grid Margin="5,2,0,2">
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="275" />
                                        <ColumnDefinition Width="250" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock  Grid.Row="0"
                                                Grid.Column="0"
                                                Text="{Binding MRN,Converter={StaticResource StringLabelConverter},ConverterParameter=MRN}" />
                                    <TextBlock Grid.Row="1"
                                               Grid.Column="0"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding OriginalVisitNumber,Converter={StaticResource StringLabelConverter},ConverterParameter='Original Visit Number'}" />
                                    <TextBlock Grid.Row="2"
                                               Grid.Column="0"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding OriginalAdmitDate,Converter={StaticResource StringLabelConverter},ConverterParameter='Original Admit Date'}" />
                                    <TextBlock Grid.Row="3"
                                               Grid.Column="0"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding OriginalReason,Converter={StaticResource StringLabelConverter},ConverterParameter='Original Reason'}" />
                                    <TextBlock Grid.Row="1"
                                               Grid.Column="1"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding ReAdmitVisitNumber,Converter={StaticResource StringLabelConverter},ConverterParameter='ReAdmit Visit Number'}" />
                                    <TextBlock Grid.Row="2"
                                               Grid.Column="1"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding ReAdmitDate,Converter={StaticResource StringLabelConverter},ConverterParameter='Readmit Date'}" />
                       开发者_如何学运维             <TextBlock Grid.Row="3"
                                               Grid.Column="1"
                                               Style="{StaticResource SearchResultsTextBlockStyle }"
                                               Text="{Binding ReAdmitReason,Converter={StaticResource StringLabelConverter},ConverterParameter='ReAdmit Reason'}" />
                                </Grid>

                            </toolkit:HeaderedContentControl>
                        </Border>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>


The actual fix involved some code shuffling, i moved the actual results list objects into a collection of viewModels and put the code for the button command in that viewModel as opposed to the parent VM. This allows for much more flexibility.

using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using WavelengthIS.Silverlight.Core.Helpers;

namespace ReadmissionTrackingApplication.Client.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public partial class ReadmitPatientListViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the ReadmitPatientListViewModel class.
        /// </summary>

        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}

        #region Declarations

        ICommand _openSurveyCommand;
        Messenger _messenger = Messenger.Default;

        #endregion

        #region Command Properties
        public ICommand OpenSurveyCommand
        {
            get
            {
                if (_openSurveyCommand == null)
                {
                    _openSurveyCommand = new RelayCommand(() => OnSurveyCommandExecute());
                }
                return _openSurveyCommand;
            }
            private set { }
        }
        #endregion

        #region Command Methods
        private void OnSurveyCommandExecute()
        {
            Wait.Begin("Loading Patient List...");
            _messenger.Send<ReadmitPatientListViewModel>(this);
            _messenger.Send<Messages.NavigationRequest<SubClasses.URI.PageURI>>(GetNavRequest_QUESTIONAIRRESHELL());

        }
        #endregion

        #region Properties

        #endregion


        private static Messages.NavigationRequest<SubClasses.URI.PageURI> GetNavRequest_QUESTIONAIRRESHELL()
        {
            Messages.NavigationRequest<SubClasses.URI.PageURI> navRequest =
                new Messages.NavigationRequest<SubClasses.URI.PageURI>(
                    new SubClasses.URI.PageURI(Helpers.PageLinks.QUESTIONAIRRESHELL, System.UriKind.Relative));
            return navRequest;
        }

        partial void OnCreated()
        {

        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜