viewmodel에 대한 데이터 템플릿에 정의 된 usercontrol에 대한 viewmodel이 있습니다. UserControl의 'GridViewData'속성을 viewmodel의 'Data'속성에 바인딩하고 싶습니다.여러보기 모델을 사용하여 바인딩
나는 아직도 바인딩에서 WPF에 새로운 끔찍한입니다, 너무 친절하십시오 : 페이지
가 XAML :
<Window x:Class="ReportUtility.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lite="clr-namespace:ReportUtility.Controls.LiteGrid"
xmlns:vm="clr-namespace:ReportUtility.ViewModels"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="MainWindow" Height="350" Width="525">
<!--This is the view model I want to bind to variable name is Grid: hosted in the content control below-->
<Window.Resources>
<DataTemplate DataType="{x:Type vm:LiteGridViewModel}">
<lite:LiteGrid GridViewData="{Binding ??}"/>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Content="TestButton" HorizontalAlignment="Stretch" Command="{Binding ExecuteQueryCommand}"/>
<TextBox Grid.Row="1" Text="{Binding Path=SqlCommandText, UpdateSourceTrigger=PropertyChanged}"/>
<ContentControl Content="{Binding Grid}" Grid.Row="2" Background="Red"/>
<Border Background="Aqua" Grid.Column="1" Grid.RowSpan="3"/>
<GridSplitter Grid.Column="0" Width="3" Grid.RowSpan="3"/>
</Grid>
뭔가를 할 수있다 (당신이
ClassA.ClassB.ClassC
를 참조 할 수 있습니다 의미) 귀하의 viewmodel에서 GridViewData = "{바인딩 데이터}"가 작동하지 않습니까? –또한 주 윈도우의 datacontext 인 뷰 모델을 가지고 있는데 ... 대신 바인딩하려고하지 않습니까? – ChandlerPelhams