问题描述
我有一个ContentControl,其ContentTemplate包含多个ContentControl。以下是用于第一个(外部)ContentControl的DataTemplate的基本布局(我删除了不相关的控件):
< DataTemplate x:Key =" KeyCardTemplate">
< Grid Margin =" 5"背景= QUOT;#FF89776B"宽度= QUOT; 215"高度= QUOT; 215" CornerRadius = QUOT; 15"的HorizontalAlignment = QUOT;中心" VerticalAlignment = QUOT;中心">
< Grid.ColumnDefinitions>
< ColumnDefinition Width =" 10" />
< ColumnDefinition Width =" 10" />
< ColumnDefinition Width =" *" />
< ColumnDefinition Width =" 10" />
< ColumnDefinition Width =" 10" />
< /Grid.ColumnDefinitions>
< Grid.RowDefinitions>
< RowDefinition Height =" 10" />
< RowDefinition Height =" 10" />
< RowDefinition Height =" *" />
< RowDefinition Height =" 10" />
< RowDefinition Height =" 10" />
< /Grid.RowDefinitions>
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT; 2英寸Grid.Row = QUOT 1 QUOT;的HorizontalAlignment = QUOT;中心"含量=" {结合}" />
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT; 2英寸Grid.Row = QUOT; 2英寸Grid.ColumnSpan = QUOT; 2英寸VerticalAlignment = QUOT;中心" HorizontalAlignment =" Rig
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT; 2英寸Grid.Row = QUOT; 3英寸的HorizontalAlignment = QUOT;中心" RenderTransformOrigin = QUOT; 0.5,0.5" Content =" {
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT 1 QUOT; Grid.Row = QUOT; 2英寸Grid.ColumnSpan = QUOT; 2英寸VerticalAlignment = QUOT;中心" HorizontalAlignment =" Lef
< Viewbox Grid.Column =" 2" Grid.Row = QUOT; 2英寸;>
< Grid Background =" Black" BorderBrush = QUOT;#FF444444"了borderThickness = QUOT 1 QUOT; CornerRadius = QUOT; 5英寸余量= QUOT; 3英寸填充= QUOT; 10">
< ItemsControl ItemsSource =" {Binding SquareTypes}">
< / ItemsControl>
< / Grid>
< / Viewbox>
< / Grid>
< / DataTemplate>
尝试更新时,我使用以下代码(Me.TestKeyCard是我的自定义类型的实例,WordCardType是枚举):
Dim temp As WordCardType()= Me.TestKeyCard.SquareTypes
Me.TestKeyCard.SquareTypes = Nothing
Me.cntEdit.Content = Me.TestKeyCard
Me.TestKeyCard.SquareTypes = temp
Me.cntEdit.Content = Me.TestKeyCard
如您所见,我设置了SquareTypes属性(如你可以在我的XAML中看到,这是ItemsControl的ItemsSource绑定的属性)到Nothing,将它分配给ContentControl的Content属性(Me.cntEdit.Content),然后恢复该值,
再次分配它。这使ItemsControl更新(因为SquareTypes是它的ItemsSource绑定的属性),但内部ContentControl没有更新。我对解决方案的第一个想法是做类似的事情来使内部ContentControl(s)
更新,但由于内部ContentControl的内容没有绑定到特定属性(Content =" {Binding }"),这似乎不起作用。任何人都可以帮我弄清楚该怎么办?谢谢。
Nathan Sokalski [email protected] http://www.nathansokalski.com/
I have a ContentControl whose ContentTemplate contains several ContentControl(s). Here is the basic layout of DataTemplate used for the first (outer) ContentControl (I have removed irrelevant controls):
<DataTemplate x:Key="KeyCardTemplate"> <Grid Margin="5" Background="#FF89776B" Width="215" Height="215" CornerRadius="15" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="10"/> <ColumnDefinition Width="10"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="10"/> <ColumnDefinition Width="10"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="10"/> <RowDefinition Height="10"/> <RowDefinition Height="*"/> <RowDefinition Height="10"/> <RowDefinition Height="10"/> </Grid.RowDefinitions> <ContentControl ContentTemplate="{StaticResource KeyCardColorTemplate}" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center" Content="{Binding}"/> <ContentControl ContentTemplate="{StaticResource KeyCardColorTemplate}" Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Rig <ContentControl ContentTemplate="{StaticResource KeyCardColorTemplate}" Grid.Column="2" Grid.Row="3" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" Content="{ <ContentControl ContentTemplate="{StaticResource KeyCardColorTemplate}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Lef <Viewbox Grid.Column="2" Grid.Row="2"> <Grid Background="Black" BorderBrush="#FF444444" BorderThickness="1" CornerRadius="5" Margin="3" Padding="10"> <ItemsControl ItemsSource="{Binding SquareTypes}"> </ItemsControl> </Grid> </Viewbox> </Grid> </DataTemplate>
When attempting to update this, I use the following code (Me.TestKeyCard is an instance of a custom type of mine, and WordCardType is an Enum):
Dim temp As WordCardType() = Me.TestKeyCard.SquareTypes Me.TestKeyCard.SquareTypes = Nothing Me.cntEdit.Content = Me.TestKeyCard Me.TestKeyCard.SquareTypes = temp Me.cntEdit.Content = Me.TestKeyCard
As you can see, I set the SquareTypes property (as you can see in my XAML, this is the property that the ItemsControl's ItemsSource is bound to) to Nothing, assign it to the ContentControl's Content property (Me.cntEdit.Content), then restore the value and assign it again. This makes the ItemsControl update (since SquareTypes is the property it's ItemsSource is bound to), but the inner ContentControl(s) are not being updated. My first thought for a solution was to do something similar to make the inner ContentControl(s) update, but since the Content of the inner ContentControl(s) is not bound to a specific property (Content="{Binding}"), this did not seem to work. Can anybody help me figure out what to do? Thanks.
Nathan Sokalski [email protected] http://www.nathansokalski.com/
这篇关于[UWP] [XAML] [VB]嵌套的ContentControl(s)未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!