相关疑难解决方法(0)

在WPF UserControl中附加ICommand

我实现了一个带有图像的简单按钮:

    <Button Command="{Binding ButtonCommand, ElementName=ImageButtonControl}">
        <StackPanel Orientation="Horizontal">
            <Image Source="{Binding ButtonImage, ElementName=ImageButtonControl}"/>
            <TextBlock Text="{Binding ButtonText, ElementName=ImageButtonControl}" Margin="2,0,0,0"/>
        </StackPanel>
    </Button>
Run Code Online (Sandbox Code Playgroud)

如您所见,我公开了一个ButtonCommand属性,以便能够将ICommand附加到此UserControl:

public partial class ImageButton : UserControl
{
    /// <summary>
    /// The dependency property that gets or sets the source of the image to render.
    /// </summary>
    public static DependencyProperty ImageSourceProperty = 
        DependencyProperty.Register("ButtonImage", typeof(ImageSource), typeof(ImageButton));

    public static DependencyProperty TextProperty =
        DependencyProperty.Register("ButtonText", typeof(string), typeof(ImageButton));

    public static DependencyProperty ButtonCommandProperty =
        DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(ImageButton));

    public ImageButton()
    {
        this.DataContext = this;
        InitializeComponent();
    }

    /// <summary>
    /// …
Run Code Online (Sandbox Code Playgroud)

c# wpf user-controls mvvm

7
推荐指数
1
解决办法
2万
查看次数

在WPF中创建自定义"+"按钮

我一直在尝试在WPF中创建自定义加号按钮.我只想要+符号,但我没有运气获得Path数据变量.我看过Path语法,但我仍然遇到麻烦.

这是我到目前为止所做的,但它太大了.我需要一个更小,更成比例的按钮:

<Path
        Stretch="Fill"
        Opacity="1"
        x:Name="path"
        StrokeThickness="10"
        RenderTransformOrigin="0.5,0.5" Margin="39,56.75,39,65.25" Data="M0,5L10,5 M5,5L5,1z" >
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里有什么问题?

谢谢

wpf

4
推荐指数
4
解决办法
7293
查看次数

WPF TriState图像按钮

有没有人有任何创建三态图像按钮的指针?

我有以下内容,但我真正想要做的是拥有一个具有多个ImageSource属性的控件 <Controls.TristateButton Image="" HoverImage="" PressedImage="" />

<Style TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <StackPanel Orientation="Horizontal" >
                    <Image Name="PART_Image" Source="path to normal image" />
                </StackPanel>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Source" Value="path to mouse over image" TargetName="PART_Image"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Source" Value="path to pressed image" TargetName="PART_Image"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

wpf image button

3
推荐指数
1
解决办法
2万
查看次数

wpf按钮与前景和背景作为图像

在我的wpf应用程序中,我有一个按钮.我希望按钮像背景一样有图像,而forground也有图像.这该怎么做?

谢谢,卡恩

wpf

2
推荐指数
1
解决办法
3387
查看次数

标签 统计

wpf ×4

button ×1

c# ×1

image ×1

mvvm ×1

user-controls ×1