0

背後にViewModelがあるユーザーコントロールがあります...

codebehindのユーザーコントロールのコンストラクターは次のようになります。

 public ClientListingVM()
        {
            ClientListingViewModel model = new ClientListingViewModel();//this is my model
            DataContext = model;
            InitializeComponent();
        }

コントロールには、DataGridとPagerが含まれています。

 <controls:DataGrid x:Name="ClientGrid" MinHeight="100" IsReadOnly="True"  
                                      ItemsSource="{Binding Path=Data}"
                                      AutoGenerateColumns="False" MinWidth="190" Height="200">
                        <controls:DataGrid.Columns>
                            <!--<controls:DataGridTextColumn Binding="{Binding ClientId}" Header="Client ID"/>-->
                            <controls:DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName"/>
                            <controls:DataGridTextColumn Binding="{Binding LastName}" Header="LastName"/>
                            <controls:DataGridTextColumn Binding="{Binding Phone}" Header="Phone"/>
                            <controls:DataGridTextColumn Binding="{Binding Email}" Header="Email"/>
                            <controls:DataGridTextColumn Binding="{Binding Address}" Header="Address"/>
                            <controls:DataGridTextColumn Binding="{Binding CNP}" Header="CNP"/>
                            <controls:DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
                            <controls:DataGridTextColumn Binding="{Binding CUI}" Header="CUI"/>
                            <controls:DataGridTextColumn Binding="{Binding CIF}" Header="CIF"/>
                            <controls:DataGridTextColumn Binding="{Binding BankAccount}" Header="BankAccount"/>
                            <controls:DataGridTemplateColumn Header="Photo">
                                <controls:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Image x:Name="ClientImage" Source="{Binding Picture, Converter={StaticResource ImageConverter}}"  Stretch="UniformToFill" Width="150" Height="150" />
                                    </DataTemplate>
                                </controls:DataGridTemplateColumn.CellTemplate>
                            </controls:DataGridTemplateColumn>
                            <controls:DataGridTemplateColumn Header="Action">
                                <controls:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="DeleteClient" Click="DeleteClient_Click" CommandParameter="{Binding ClientId}" Content="Delete"></Button>
                                    </DataTemplate>
                                </controls:DataGridTemplateColumn.CellTemplate>
                            </controls:DataGridTemplateColumn>
                        </controls:DataGrid.Columns>
                    </controls:DataGrid>
                    <controls:DataPager x:Name="ContactPager" PageSize="5" Source="{Binding Path=Data}" MinWidth="190"></controls:DataPager>

私のモデルは次のようになります。

public class ClientListingViewModel : ViewModelBase
    {

        private DomainDataSource _clientDataSource;

        public ClientListingViewModel()
        {
            ClientDataSource.Load();
        }

        public DomainDataSource ClientDataSource 
        {
            get {
                if (_clientDataSource == null) {
                    _clientDataSource = new DomainDataSource();
                    _clientDataSource.DomainContext = new ClientDomainContext();
                    //_clientDataSource.AutoLoad = true;
                    _clientDataSource.LoadSize = 10;
                    _clientDataSource.QueryName = "GetClientsQuery";
                    _clientDataSource.LoadedData += new EventHandler<LoadedDataEventArgs>(_clientDataSource_LoadedData);
                }
                return _clientDataSource;
            }
        }

        void _clientDataSource_LoadedData(object sender, LoadedDataEventArgs e){
            OnPropertyChanged("Data");
        }

        public DomainDataSourceView Data
        {
            get { return ClientDataSource.DataView; }

        }
    }

問題は、バインディングが機能せず、その理由を理解できないことです..... xamlにdomaindatasourceコントロールを追加し、それにバインディングを作成すると、正常に機能します...

<riacontrols:DomainDataSource x:Name="ClientDataSource"  AutoLoad="True" LoadSize="10"  QueryName="GetClients" >
                    <riacontrols:DomainDataSource.DomainContext>
                        <ds:ClientDomainContext/>
                    </riacontrols:DomainDataSource.DomainContext>
                </riacontrols:DomainDataSource>
  <controls:DataGrid x:Name="ClientGrid" MinHeight="100" IsReadOnly="True"  
                                      ItemsSource="{Binding  ElementName=ClientDataSource, Path=DataView}"
                                       AutoGenerateColumns="False" MinWidth="190" Height="350">
                        <controls:DataGrid.Columns>
                            <!--<controls:DataGridTextColumn Binding="{Binding ClientId}" Header="Client ID"/>-->
                            <controls:DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName"/>
                            <controls:DataGridTextColumn Binding="{Binding LastName}" Header="LastName"/>
                            <controls:DataGridTextColumn Binding="{Binding Phone}" Header="Phone"/>
                            <controls:DataGridTextColumn Binding="{Binding Email}" Header="Email"/>
                            <controls:DataGridTextColumn Binding="{Binding Address}" Header="Address"/>
                            <controls:DataGridTextColumn Binding="{Binding CNP}" Header="CNP"/>
                            <controls:DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
                            <controls:DataGridTextColumn Binding="{Binding CUI}" Header="CUI"/>
                            <controls:DataGridTextColumn Binding="{Binding CIF}" Header="CIF"/>
                            <controls:DataGridTextColumn Binding="{Binding BankAccount}" Header="BankAccount"/>
                            <controls:DataGridTemplateColumn Header="Photo">
                                <controls:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Image x:Name="ClientImage" Source="{Binding Picture, Converter={StaticResource ImageConverter}}"  Stretch="UniformToFill" Width="150" Height="150" />
                                    </DataTemplate>
                                </controls:DataGridTemplateColumn.CellTemplate>
                            </controls:DataGridTemplateColumn>
                            <controls:DataGridTemplateColumn Header="Action">
                                <controls:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button x:Name="DeleteClient" Click="DeleteClient_Click" CommandParameter="{Binding ClientId}" Content="Delete"></Button>
                                    </DataTemplate>
                                </controls:DataGridTemplateColumn.CellTemplate>
                            </controls:DataGridTemplateColumn>
                        </controls:DataGrid.Columns>
                    </controls:DataGrid>
                    <controls:DataPager x:Name="ContactPager" PageSize="5" Source="{Binding ElementName=ClientDataSource, Path=Data}" MinWidth="190"></controls:DataPager>

ビューモデルからこれを機能させるにはどうすればよいですか?

4

1 に答える 1

1

ClientDataSource.Dataにバインドすることで問題を修正しました

 <controls:DataGrid x:Name="ClientGrid" MinHeight="100" IsReadOnly="True"  
                                      ItemsSource="{Binding Path=ClientDataSource.Data}"
                                      AutoGenerateColumns="False" MinWidth="190" Height="200">
于 2010-11-17T11:12:47.450 に答える