[UWP] [XAML] [VB]嵌套的ContentControl(s)未更新 [英] [UWP][XAML][VB]Nested ContentControl(s) not Updating

查看:109
本文介绍了[UWP] [XAML] [VB]嵌套的ContentControl(s)未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ContentControl,其ContentTemplate包含多个ContentControl。以下是用于第一个(外部)ContentControl的DataTemplate的基本布局(我删除了不相关的控件):

< DataTemplate x:Key =" KeyCardTemplate"> 
< Grid Margin =" 5"背景= QUOT;#FF89776B"宽度= QUOT; 215"高度= QUOT; 215" CornerRadius = QUOT; 15"的Horizo​​ntalAlignment = 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;的Horizo​​ntalAlignment = QUOT;中心"含量=" {结合}" />
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT; 2英寸Grid.Row = QUOT; 2英寸Grid.ColumnSpan = QUOT; 2英寸VerticalAlignment = QUOT;中心" Horizo​​ntalAlignment =" Rig
< ContentControl ContentTemplate =" {StaticResource KeyCardColorTemplate}" Grid.Column = QUOT; 2英寸Grid.Row = QUOT; 3英寸的Horizo​​ntalAlignment = 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;中心" Horizo​​ntalAlignment =" 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 njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Nathan Sokalski,


我无法用你的代码片段重现问题。


形成代码片段,内部ContentControl的DataContext是外部ContentControl。您想将内部ContentControl的内容绑定到外部ContentControl的内容吗?如果是这样,这个
{绑定内容} 是否有效?


如果您可以分享我的样本以找出问题,那会更好。请删除所有敏感代码和一个可以重现问题的简单演示就足够了。 


祝你好运,


Roy


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 njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hi Nathan Sokalski,

I could not reproduce the problem with your code snippet.

Form the code snippet, the inner ContentControl's DataContext is the outer ContentControl. Do you want to bind inner ContentControl's content to outer ContentControl's content? If so, does this {binding content} work?

It would be better if you could share me a sample to find out the problem. Please delete all the sensitive code and a simple demo that could reproduce the problem will be enough. 

Best regards,

Roy


这篇关于[UWP] [XAML] [VB]嵌套的ContentControl(s)未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆