假设我有两个可以引用第三个UI对象的类(在本例中是一个按钮).
此外,父类可以包含子类的元素.
如果它们都以相同的方式绑定到同一个控件,则子节点会失败但父节点会成功.
父母:
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) 我有枚举
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) 我在.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)
我该怎么做?
我正在尝试用故事板管理一个动画,它是一个闪烁的标签,并且实现了这个效果我已经使用了这个代码(动画我首选只在后面的代码中工作):我宣布我的故事板;
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) 我有以下问题:我Image在WPF中使用组件。我加载我的Image那map对我来说。我要说的是Button,如果单击,将允许我单击map并画点。该点应该是“唯一的”,因此它应该记住坐标/描述(我将其存储在数据库中)。坐标只能从该图像读取,而不能从整个表格读取。OnMouseClick创建积分后,我需要活动。
我应该使用/了解如何做呢?
目前我正在研究函数,我无法真正找出以下代码的错误.无论"密码"的价值是什么,我总是得到"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) 我需要帮助用用户控件替换一些 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) 我阅读了SetTraceLevel() 方法的文档,但无法从该 2 行文档中获得任何信息。
任何人都可以对此有所了解。
为什么我收到以下错误:"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为未来版本.
wpf ×8
c# ×6
xaml ×3
binding ×1
draw ×1
enums ×1
javascript ×1
logical-tree ×1
storyboard ×1
styles ×1
syntax ×1
trace ×1
visual-tree ×1