如何在WPF中运行时填充颜色 [英] How to fill a color at runtime in WPF

查看:406
本文介绍了如何在WPF中运行时填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   viewbox     width   =  48    height   =  48    margin   =  0 20 0 0 >  
< 画布 宽度 = 24 高度 = 24 >
< path x:name = myPath data = M12,11A1,1 0 0,0 11,12A1,1 0 0,0 Fill = green = / >< br mode = hold = /> < / Canvas>< br mode = xmlns:x = #unknown > < / path > < / viewbox >

解决方案

我可以给你一个一般建议:看看你在XAML中编写的内容在运行时是如何工作的,只需看看自动生成的代码。用windows创建一些项目,页面和/或用户控件使用XAML并构建它,确保它工作。所有这些XAML代码然后用于自动生成一些代码,在您的情况下,C#代码,进一步编译。



构建项目时,默认情况下,您可以在s下找到自动生成的代码ub-directoryobj,它是在项目的子目录下创建的。学习它。它在所有情况下都很有用。如果以后你还有其他一些问题,你可以再做一次。



另一种方法就是只读一些基本原理来阅读MSDN文档。这是您创建 Path 对象并设置其属性的方法:

Path Class(System.Windows.Shapes)

包括填写 Shape.Fill属性(System.Windows.Shapes)



这是你如何将它添加到画布:

Panel.Children Property(System.Windows.Controls)

UIElementCollection类(System.Windows.Controls)

UIElementCollection.Add方法(UIElement)(System.Windows.Controls)



依旧......



-SA

<viewbox width="48" height="48" margin="0 20 0 0">
   <Canvas Width="24" Height="24">
   <path x:name="myPath" data="M12,11A1,1 0 0,0 11,12A1,1 0 0,0 Fill=" green=" /><br mode=" hold=" />  </Canvas><br mode=" xmlns:x="#unknown"></path></viewbox>

解决方案

I can give you one general advice: to see how something you write in XAML works during runtime, simply look at the auto-generated code. Create some project with windows, pages and/or user controls using XAML and build it, make sure it works. All such XAML code is then used to auto-generate some code, in your case, C# code, which is further compiled.

When your project is built, by default, you can find that auto-generated code under the sub-directory "obj" which is created under the sub-directory of your project. Learn it. It is useful in all cases. If later you have some other problems like that, you can do it again.

Another way is just reading MSDN documentation knowing only some basic principles. This is how you create a Path object and setup its properties:
Path Class (System.Windows.Shapes),
including Fill: Shape.Fill Property (System.Windows.Shapes).

This is how you add it to an instance of Canvas:
Panel.Children Property (System.Windows.Controls),
UIElementCollection Class (System.Windows.Controls),
UIElementCollection.Add Method (UIElement) (System.Windows.Controls).

And so on…

—SA


这篇关于如何在WPF中运行时填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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