小编Anj*_*han的帖子

当父成功将子元素绑定到另一个元素时,为什么绑定失败?

假设我有两个可以引用第三个UI对象的类(在本例中是一个按钮).

此外,父类可以包含子类的元素.

如果它们都以相同的方式绑定到同一个控件,则子节点会失败但父节点会成功.

这是WPF中的错误吗?


父母:

class MyFrameworkElement : FrameworkElement
{
    // A depenedency property that will contain a child element sub-element
    private static readonly DependencyProperty ChildElementProperty =
                    DependencyProperty.Register("ChildElement",
                    typeof(MyChildElement),
                    typeof(MyFrameworkElement),
                    new PropertyMetadata());

    [Category("ChildProperties")]
    public MyChildElement ChildElement
    {
        set { SetValue(ChildElementProperty, value); }
        get { return (MyChildElement)GetValue(ChildElementProperty); }
    }


    // Now, a reference to some other control, in this case we will bind a button to it!
    public UIElement ButtonReferenceInParent
    {
        get { return (UIElement)GetValue(ButtonReferenceInParentProperty); }
        set { SetValue(ButtonReferenceInParentProperty, value); …
Run Code Online (Sandbox Code Playgroud)

wpf xaml binding visual-tree logical-tree

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

WPF XAML 传递给 ConverterParameter 枚举数组

我有枚举

public enum DocumentTypes
{
    First, Second, Third, Fourth
}
Run Code Online (Sandbox Code Playgroud)

如何传递的值enum<sys:Enum></sys:Enum>

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1.Converters"
xmlns:enums="clr-namespace:WpfApplication1.Enums"
xmlns:sys="clr-namespace:System;assembly=mscorlib"

       <Label Content="Test2">
            <Label.Visibility>
                <MultiBinding Converter="{StaticResource Converter}">
                    <MultiBinding.ConverterParameter>
                        <x:Array Type="{x:Type sys:Enum}">
                            <sys:Enum></sys:Enum>
                        </x:Array>
                    </MultiBinding.ConverterParameter>
                    <Binding ElementName="First" Path="IsChecked" />
                    <Binding ElementName="Second" Path="IsChecked" />
                    <Binding ElementName="Third" Path="IsChecked" />
                    <Binding ElementName="Fourth" Path="IsChecked" />
                </MultiBinding>
            </Label.Visibility>
        </Label>
Run Code Online (Sandbox Code Playgroud)

c# wpf enums xaml

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

仅在鼠标离开时自动反转为原始颜色

我在.Net framework 4中使用WPF.
我创建了一个背景颜色为X的按钮.
我为按钮创建了一个样式,在IsMouseOver上启动ColorAnimation,将背景颜色更改为蓝色.

如果IsMouseOver为假(鼠标在按钮上没有记录器),我想将按钮背景恢复为颜色X.

示例代码:

<Trigger Property="IsMouseOver" Value="True">
    <Trigger.EnterActions>
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation Duration="0:0:0.5" Storyboard.TargetName="MyButton" Storyboard.TargetProperty="Fill.Color"  To="Blue"/>
            </Storyboard>
        </BeginStoryboard>
    </Trigger.EnterActions>
</Trigger>
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

c# wpf styles coloranimation wpf-animation

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

无法停止故事板动画,我只能开始它

我正在尝试用故事板管理一个动画,它是一个闪烁的标签,并且实现了这个效果我已经使用了这个代码(动画我首选只在后面的代码中工作):我宣布我的故事板;

    public partial class Example: Page
    {
         public Storyboard LabelStoryboard=new Storyboard(); 
    }
Run Code Online (Sandbox Code Playgroud)

然后我发布动画:

 private void FlashWinLabel(){

        DoubleAnimation Flash= new DoubleAnimation();
        Flash.Duration = TimeSpan.FromMilliseconds(400);
        Flash.From = 1.0d;
        Flash.To = 0.0d;
        Flash.RepeatBehavior = RepeatBehavior.Forever;
        WinLabel.BeginAnimation(Label.OpacityProperty, Flash);

        SolidColorBrush myAnimatedBrush = new SolidColorBrush();
        myAnimatedBrush.Color = Colors.White;
        WinLabel.Foreground = myAnimatedBrush;


        this.RegisterName("MyAnimatedBrush", myAnimatedBrush);

        ColorAnimation LabelColorAnimation = new ColorAnimation();
        LabelColorAnimation.To = Colors.GreenYellow;
        LabelColorAnimation.Duration = TimeSpan.FromMilliseconds(200);
        LabelColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
        LabelColorAnimation.AutoReverse = true;
        Storyboard.SetTargetName(LabelColorAnimation, "MyAnimatedBrush");
        Storyboard.SetTargetProperty(
            LabelColorAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

        LabelStoryboard.Children.Add(LabelColorAnimation);

        WinLabel.BeginStoryboard(LabelStoryboard);


    }
Run Code Online (Sandbox Code Playgroud)

所有这一切都有效,直到这一点,当我试图通过按下屏幕上的按钮来停止故事板时出现问题:

     private void StopStoryBoard()
    {
        LabelStoryboard.Stop();

    } …
Run Code Online (Sandbox Code Playgroud)

c# wpf storyboard wpf-animation doubleanimation

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

如何在带有事件的运行时Image(WPF)中的图像上绘制点

我有以下问题:我Image在WPF中使用组件。我加载我的Imagemap对我来说。我要说的是Button,如果单击,将允许我单击map并画点。该点应该是“唯一的”,因此它应该记住坐标/描述(我将其存储在数据库中)。坐标只能从该图像读取,而不能从整个表格读取。OnMouseClick创建积分后,我需要活动。

我应该使用/了解如何做呢?

c# wpf draw

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

我的代码有什么问题?

目前我正在研究函数,我无法真正找出以下代码的错误.无论"密码"的价值是什么,我总是得到"NICE"

var passValid = function (password) {
    return password.length;
};

if (passValid<5){
    console.log("ERROR");
}
else{
    console.log("NICE");
}

passValid("somevalue");
Run Code Online (Sandbox Code Playgroud)

javascript syntax

0
推荐指数
1
解决办法
84
查看次数

WPF 为 TabItem 创建 UserControl

我需要帮助用用户控件替换一些 xaml 代码。我在主窗口中有两个选项卡,我想将第二个选项卡(显示为 Header=WCF)放在用户控件中。这是我的代码:

<Window x:Class="TesterTool.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:gif="http://wpfanimatedgif.codeplex.com"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:helpers="clr-namespace:TesterTool"
    xmlns:da ="clr-namespace:TesterTool.DatabaseAccess"
    xmlns:converters="clr-namespace:TesterTool.Converters"
    xmlns:vm="clr-namespace:TesterTool"
    Title="TestingTool v1.00" Height="350" Width="725"
    Icon="Icon.ico">

<Window.Resources>
    <converters:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
    <converters:InvertedBoolVisibilityConverter x:Key="InvertedBoolVisibilityConverter"/>
</Window.Resources>

<TabControl>
    <TabItem Header="WPF" Margin="-2,0" Height="22" VerticalAlignment="Bottom">
        <Grid>
            <Grid.Background>
                <ImageBrush ImageSource="image.png"/>
            </Grid.Background>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Image gif:ImageBehavior.AnimatedSource="332.gif"

            Width="152"
            Height="39"
           Margin="10,69,194,37"
           Grid.Row="1"
           Visibility="{Binding IsLoading, Converter={StaticResource BoolVisibilityConverter}}"/>
            <TextBox x:Name="tb1"
             Text ="{Binding BoxSerialNumber}"
             Height="23" Margin="128,26,0,0"
             TextWrapping="Wrap"
             VerticalAlignment="Top"
             HorizontalAlignment="Left" Width="220"
             />
            <TextBox x:Name="tbn2"
             Visibility="{Binding IsViewLogSelected, Converter={StaticResource InvertedBoolVisibilityConverter}}"
             Height="23" Margin="128,73,8,0"
             TextWrapping="Wrap"
             Text="{Binding HardwareID}"
             VerticalAlignment="Top"
             RenderTransformOrigin="0.494,0.478"/> …
Run Code Online (Sandbox Code Playgroud)

c# wpf user-controls

0
推荐指数
1
解决办法
4465
查看次数

System.Diagnostics.PresentationTraceSources.SetTraceLevel() 方法的使用

我阅读了SetTraceLevel() 方法的文档,但无法从该 2 行文档中获得任何信息。

任何人都可以对此有所了解。

wpf trace

0
推荐指数
1
解决办法
914
查看次数

Windows演示基础项目wpf不支持int16

为什么我收到以下错误:"Windows演示基础项目wpf不支持Int16."

我正在阅读以下MSDN文本: MSDN TEXT重新分级基元映射

下面是我的简单代码:

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <x:Int16 x:Key="cnst">12</x:Int16>        
    </Window.Resources>

    <Grid>

    </Grid>

</Window>
Run Code Online (Sandbox Code Playgroud)

为什么这段代码不起作用?需要做些什么才能让它发挥作用.我的猜测:2006需要替换2009为未来版本.

c# wpf xaml

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