System.Drawing.Font 和 .Bitmap 类型的 DependencyProperties 的默认值

发布于 2024-12-26 20:28:17 字数 836 浏览 3 评论 0原文

这是我的代码:

public class CustomWidget
{
    public System.Drawing.Color Value
    {
        get { return (System.Drawing.Color)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(System.Drawing.Color), typeof(Color), new UIPropertyMetadata(0));

    public System.Drawing.Font Valuee
    {
        get { return (System.Drawing.Font)GetValue(ValueeProperty); }
        set { SetValue(ValueeProperty, value); }
    }
    public static readonly DependencyProperty ValueeProperty =
        DependencyProperty.Register("Valuee", typeof(System.Drawing.Font), typeof(Font), new UIPropertyMetadata(0));
}

对于字体,我可以设置默认字体,我认为没有其他方法,但是位图呢?我绝对必须在我的项目中获取一个将被引用为默认值的位图吗?

Here is the code I have :

public class CustomWidget
{
    public System.Drawing.Color Value
    {
        get { return (System.Drawing.Color)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }
    public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(System.Drawing.Color), typeof(Color), new UIPropertyMetadata(0));

    public System.Drawing.Font Valuee
    {
        get { return (System.Drawing.Font)GetValue(ValueeProperty); }
        set { SetValue(ValueeProperty, value); }
    }
    public static readonly DependencyProperty ValueeProperty =
        DependencyProperty.Register("Valuee", typeof(System.Drawing.Font), typeof(Font), new UIPropertyMetadata(0));
}

For the Font, I can set a default Font, there is not other way I think, but what about the Bitmap ? Do I absolutelyu have to get a Bitmap in my project that will be referenced for the default value ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2025-01-02 20:28:17

不,您可以简单地使用null

No, you can simply use null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文