我正在DependencyProperty
为我的 Avalon 坞站控制器开发一个。这是我目前正在处理的一些示例代码。
要求是:在一个类中创建所有依赖属性,并在 View 中访问该属性。像这样的东西。
<Button isPaneVisible="true"> or <Button isPaneVisible="{Staticresource path=name, Mode=twoway">
你能帮我解决这个问题吗?
namespace Avatar.UI.ViewModel
{
internal class DependencyPropertyClass : DependencyObject
{
public static readonly DependencyProperty IsPaneVisibleProperty =
DependencyProperty.RegisterAttached("IsPaneVisible", typeof(bool), typeof(DependencyPropertyClass),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsPaneVisible_PropertyChanged));
private static void IsPaneVisible_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
/// <summary>
/// Sets the IsPaneVisible for an element.
/// </summary>
public bool IsPaneVisible
{
get { return (bool)GetValue(IsPaneVisibleProperty); }
set
{
SetValue(IsPaneVisibleProperty, value);
}
}
}
}
<UserControl x:Class="Avatar.UI.View.ContentView"
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"
mc:Ignorable="d"
xmlns:avalonDock="http://avalondock.codeplex.com"
xmlns:local="clr-namespace:Avatar.UI.ViewModel"
d:DesignHeight="300" d:DesignWidth="300">
<Button IsPaneVisible="true"></Button
</UserControl>