Tho*_*n79 15 data-binding wpf mvvm attached-properties
希望这不是一个骗局.
我希望能够在XAML中执行以下操作:
<DataTemplate DataType="{x:Type TestApp:ButtonVM}">
<Button
Grid.Column="{Binding GridColumn}"
Grid.Row="{Binding GridRow}"
Content="{Binding Path=Info}"
/>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
内容绑定工作正常,但Grid.Column和Grid.Row根本不存在于生成的对象中.甚至在我没有绑定的情况下将它们设置为某个值时(例如在Grid.Column ="1"中).我已经窥探了应用程序,看到我的网格中没有人设置Grid.Column和Grid.Row.
有任何想法吗?
Tho*_*n79 22
在博客的帮助下解决了这个问题.
据我所知,你根本无法在里面做附加的属性绑定.
以下解决了瞬间的问题(ItemContainerStyle!):
<DataTemplate DataType="{x:Type TestApp:GridVM}">
<ItemsControl ItemsSource="{Binding Path=Children}">
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value="{Binding GridRow}" />
<Setter Property="Grid.Column" Value="{Binding GridColumn}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True" Style="{Binding Path=Style}">
<Grid.RowDefinitions>
<RowDefinition Height=".5*" />
<RowDefinition Height=".5*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".5*" />
<ColumnDefinition Width=".5*" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12661 次 |
| 最近记录: |