WPF 精修篇 动态资源

2021-01-23 03:13

阅读:677

标签:oid   object   code   word   fill   onclick   near   width   class   

原文:WPF 精修篇 动态资源

动态资源 使用 DynamicResource 关键字

静态 就是 StaticResource

原则上是 能用静态就用静态 动态会让前台界面压力很大~

 

动态资源引用 就是可以在后台改变资源 显示不同的样式  资源是一样的 就看关键字用什么

效果 

技术图片

 

  1. "RectFill" EndPoint="0.5,1" StartPoint="0.5,0">
  2. "BurlyWood" Offset="0"/>
  3. "White" Offset="1"/>
  4. "{ DynamicResource RectFill}" HorizontalAlignment="Left" Height="76" Margin="85,70,0,0" Stroke="Black" VerticalAlignment="Top" Width="243">
  5. "R" Content="R" HorizontalAlignment="Left" Margin="377,70,0,0" VerticalAlignment="Top" Click="R_Click"/>
  6. "G" Content="G" HorizontalAlignment="Left" Margin="377,98,0,0" VerticalAlignment="Top" Click="G_Click"/>
  7. "B" Content="B" HorizontalAlignment="Left" Margin="377,130,0,0" VerticalAlignment="Top" Click="B_Click"/>

 

  1. private void R_Click(object sender, RoutedEventArgs e)
  2. {
  3. var bursh = Resources["RectFill"];
  4. if (bursh is LinearGradientBrush)
  5. {
  6. LinearGradientBrush Ibursh = (LinearGradientBrush)bursh;
  7. Ibursh = new LinearGradientBrush()
  8. {
  9. GradientStops = new GradientStopCollection()
  10. {
  11. new GradientStop(Colors.BurlyWood,0),
  12. new GradientStop(Colors.Red,1)
  13. }
  14. };
  15. Resources["RectFill"] = Ibursh;
  16. }
  17. }
  18. private void G_Click(object sender, RoutedEventArgs e)
  19. {
  20. var bursh = Resources["RectFill"];
  21. if (bursh is LinearGradientBrush)
  22. {
  23. LinearGradientBrush Ibursh = (LinearGradientBrush)bursh;
  24. Ibursh = new LinearGradientBrush()
  25. {
  26. GradientStops = new GradientStopCollection()
  27. {
  28. new GradientStop(Colors.BurlyWood,0),
  29. new GradientStop(Colors.Green,1)
  30. }
  31. };
  32. Resources["RectFill"] = Ibursh;
  33. }
  34. }
  35. private void B_Click(object sender, RoutedEventArgs e)
  36. {
  37. var bursh = Resources["RectFill"];
  38. if (bursh is LinearGradientBrush)
  39. {
  40. LinearGradientBrush Ibursh = (LinearGradientBrush)bursh;
  41. Ibursh = new LinearGradientBrush()
  42. {
  43. GradientStops = new GradientStopCollection()
  44. {
  45. new GradientStop(Colors.BurlyWood,0),
  46. new GradientStop(Colors.Blue,1)
  47. }
  48. };
  49. Resources["RectFill"] = Ibursh;
  50. }
  51. }

 

 

WPF 精修篇 动态资源

标签:oid   object   code   word   fill   onclick   near   width   class   

原文地址:https://www.cnblogs.com/lonelyxmas/p/12075517.html


评论


亲,登录后才可以留言!