标签:代码 mic rtu port ati his 修改 view 通过
动态与静态资源的区别
<Window.Resources>
<ImageBrush x:Key="TileBrush" x:Name="DynamicBrush" TileMode="Tile"
ViewportUnits="Absolute" Viewport="0 0 32 32"
ImageSource="happyface.jpg" Opacity="0.3"></ImageBrush>
</Window.Resources>
<StackPanel Margin="5">
<Button Background="{DynamicResource TileBrush}" Padding="5"
FontWeight="Bold" FontSize="14" Margin="5">Uses a Dynamic Resource</Button>
<Button Padding="5" Margin="5" Click="cmdChange_Click"
FontWeight="Bold" FontSize="14">Change the Brush</Button>
<Button Background="{StaticResource TileBrush}" Padding="5" Margin="5"
FontWeight="Bold" FontSize="14">Uses a Static Resource</Button>
</StackPanel>
private void cmdChange_Click(object sender, RoutedEventArgs e) { this.Resources["TileBrush"] = new SolidColorBrush(Colors.LightBlue); }
效果是点击按钮后,按钮的背景有所变化,因为该按钮的背景是动态DynamicResource绑定的资源,再通过代码去修改绑定的资源。
使用字典资源
标签:代码 mic rtu port ati his 修改 view 通过
原文地址:https://www.cnblogs.com/yingzilovexiaoxiong/p/14351897.html