[UWP] [XAML]从ContentTemplate设置属性 [英] [UWP][XAML]Setting Properties From Then ContentTemplate

查看:104
本文介绍了[UWP] [XAML]从ContentTemplate设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Button,它使用以下DataTemplate作为ContentTemplate:

I have a Button that uses the following DataTemplate for the ContentTemplate:

<DataTemplate>
	<Grid>
		<Grid.RowDefinitions><RowDefinition Height="Auto"/></Grid.RowDefinitions>
		<Grid.ColumnDefinitions><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
		<Image HorizontalAlignment="Center" VerticalAlignment="Center" Height="75" Stretch="Uniform" Source="Passengers/BlackPassenger.png"/>
		<TextBlock Text="{Binding Converter={StaticResource PassengerSelection}}" FontFamily="Arial" FontSize="42" Foreground="White" HorizontalAlignment="Center" OpticalMarginAlignment="TrimSideBearings" TextAlignment="Center" TextLineBounds="Tight" VerticalAlignment="Center" FontWeight="Bold" Margin="{Binding Converter={StaticResource PassengerSelection}}"/>
	</Grid>
</DataTemplate>



实际上,这是用于ContentTemplateSelector的DataTemplateSelector使用的DataTemplate之一,但所有的DataTemplate都几乎相同。在我的XAML中,我有以下内容:


Actually, this is one of the DataTemplate(s) used by the DataTemplateSelector used for the ContentTemplateSelector, but all the DataTemplate(s) are almost identical. In my XAML, I have the following:

<Button Grid.Column="0" Grid.Row="2" Content="Black 0" ContentTemplateSelector="{StaticResource PassengerSelectionTemplate}" Tag="0"/>

但是,这会给Button一个更亮的背景,如下所示:

However, this gives the Button a lighter background like the following:

注意按钮的背景(小人物)数字)比其他地区的浅绿色更暗。我要指出的是,按钮的不需要的较暗背景总是与其他
区域的浅色相关(在这种情况下,较暗和较浅的绿色,其他情况可能较暗&较浅的红色,蓝色,黄色等)。在我的代码中的任何一点,我都没有指定Button的背景,所以它显然是一个不透明度为< 1的东西。如果我包含  Background =" Transparent" Button元素中的
,我可以摆脱较暗的背景,但我想在DataTemplate(而不是每一个Button)中做到这一点。我还想避免在光标移动到Button上时显示边框之类的东西(我希望它在所有条件下看起来都是
)。谁能告诉我如何使用DataTemplate摆脱背景?谢谢。

Notice how the background of the Button(s) (the little people with numbers) is darker than the lighter green in the other areas. I am going to point out that the unwanted darker background of the Button(s) is always related to the light color in the other areas (in this case, darker & lighter green, other cases might be darker & lighter red, blue, yellow, etc.). I do not, at any point in my code, specify the background for the Button(s), so it is obviously something with an opacity of <1. If I include Background="Transparent" in the Button element, I can get rid of the darker background, but I wanted to do it in the DataTemplate (rather than every single Button). I also want to avoid having things like a border shown when the cursor is moved over the Button (I want it to look the same under all conditions). Can anybody tell me how to get rid of the background using the DataTemplate? Thanks.

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

推荐答案

您好,

您应该创建样式并指定背景颜色和VisualStaetes。然后,您可以将此样式应用于所有按钮(注意,如果您未指定x:Key属性,则默认情况下样式应用于所有按钮)。同时,对于不同的场景,您将拥有日期模板
。 

You should create style and there specify background color and VisualStaetes. Then you can apply this style to all buttons (Note if you don't specify x:Key attribute then style by default applied to all buttons). and at the same time you will have date templates for different scenarios. 


这篇关于[UWP] [XAML]从ContentTemplate设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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