C#变化的backgroundColor特定行 [英] C# Change backgroundcolor specific row
问题描述
我创建从电网应用(XAML)模板(C#Windows应用商店)的新项目。
到目前为止,我什么也没有改变模板,但我想给的backgroundColor在网格中的特定行更改。
< !code>< -
此网格作为一个根面板定义两行的页面:
*行0包含后退按钮和页面标题
*第1行包含页面布局
的其余部分 - >
<网格样式={StaticResource的LayoutRootStyle}>
< Grid.RowDefinitions>
< RowDefinition HEIGHT =140/>
< RowDefinition高度=*/>
< /Grid.RowDefinitions>
我想从0更改行的backgroundColor(其中包含页面标题)。
任何想法? !在此先感谢
这行consits:
< ! - 后退按钮和页面标题 - >
<网格和GT;
< Grid.ColumnDefinitions>
< ColumnDefinition WIDTH =自动/>
< ColumnDefinition WIDTH =*/>
< /Grid.ColumnDefinitions>
<按钮X:NAME =后退按钮点击=GoBack的IsEnabled ={结合Frame.CanGoBack,的ElementName = pageRoot}风格={StaticResource的BackButtonStyle}/>
< TextBlock的X:名称=PAGETITLE文本={StaticResource的AppName}是Grid.Column =1IsHitTestVisible =false的风格={StaticResource的PageHeaderTextStyle}/>
< /网格和GT;
您不能设置对电网的背景颜色.Row本身,而不是设置任何占据此行的背景属性。
例如
<网格样式={StaticResource的LayoutRootStyle}>
< Grid.RowDefinitions>
< RowDefinition HEIGHT =140/>
< RowDefinition高度=*/>
< /Grid.RowDefinitions>
<网格背景=红Grid.Row =0>
<&的TextBlock GT;测试与LT; / TextBlock的>
< /网格和GT;
< /网格和GT;
编辑:
更新了Silverlight的; TextBlock的没有背景,所以你必须把另一边界或网格容器里面确实有背景的控制。代码更新,以反映这一点。
I've created a new project from the Grid App (XAML) template (C# Windows Store). So far I've changed nothing in the template, but I would like to change the backgroundcolor from a specific row in the grid.
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
I would like to change the backgroundcolor from row 0 (which contains the page title). Any ideas?? Thanks in advance!
This row consits of:
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
<TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
You can't set the background color on the Grid.Row itself, instead set the Background property on whatever occupies this row.
For example
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Background="Red" Grid.Row="0">
<TextBlock>Test</TextBlock>
</Grid>
</Grid>
EDIT: Updated for Silverlight; TextBlock doesn't have Background so you have to put the control in another Border or grid container which does have background. Code updated to reflect this.
这篇关于C#变化的backgroundColor特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!