WPF UserControl内容在设计模式下不显示

问题描述

我有UserControl作为按钮,需要显示图像和文本。当我运行应用程序时,一切正常,但在设计器中文本和图像未显示。 UserControl所在的项目位于同一项目中

XAML

<UserControl x:Class="ClientHCS.controls.ucBtn"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:ClientHCS.controls"
         mc:Ignorable="d" 
         d:DesignHeight="35" d:DesignWidth="100">
    <Button Name="Btn"  Click="Btn_Click"  Padding="0">
        <StackPanel Orientation="Horizontal" >
            <Image Name="ImBtn" />
            <Label Name="lblContent"/>
        </StackPanel>
    </Button>
</UserControl>

C#

public static DependencyProperty ImgSourceProperty = DependencyProperty.Register("ImgSource",typeof(ImageSource),typeof(ucBtn),new UIPropertyMetadata(
           default(ImageSource),new PropertyChangedCallback(OnImgSourceChanged))
        );

    public ImageSource ImgSource {
        get { return (ImageSource)GetValue(ImgSourceProperty); }
        set { SetValue(ImgSourceProperty,value); 
        }
    }
    private static void OnImgSourceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) {
        ucBtn ctrl = (ucBtn)d;
        ctrl.ImBtn.source = (ImageSource)e.NewValue;

    }

我将此控件添加到结果表单中

<controls:ucBtn DockPanel.Dock="Top" HorizontalAlignment="Center" x:Name="btnClose" Margin="140,5,59,5" Click="btnClose_Click" BtnContent="Close" ImgSource='\icons\Close.ico' Width="93" Height="19"/>

添加了DependencyProperty,设置了PropertyChangedCallback,但在Studio构造函数中看到了空按钮。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...