0
WPF에서 작업하면서 사용자 정의 사용자 정의 컨트롤을 작성합니다. 클래스의 속성 값을 변경할 때 Border 요소의 background 속성을 변경하려고합니다. 지금 나는 DP에 바인딩하는 작업을하고 있는데, 제안이 더 좋은 방법이라면 가능하다. 여기 문제 WPF에서 Brush 속성에 바인딩
는public partial class MyControl : UserControl
{
public static DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(MyControl));
public static DependencyProperty CoreBackgroundProperty = DependencyProperty.Register("CoreBackground", typeof(Brush), typeof(MyControl));
public MyControl()
{
CoreBackground = new SolidColorBrush(Color.FromArgb(0, 255, 245, 104));
InitializeComponent();
Margin = new Thickness(5);
}
public Brush CoreBackground
{
get { return (Brush)GetValue(CoreBackgroundProperty); }
set { SetValue(CoreBackgroundProperty, value); }
}
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
private set { SetValue(IsSelectedProperty, value); }
}
}
대신, 배경은 투명 나오는 ... UserControl을
<UserControl x:Class="MyProject.MyControl"
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:js="clr-namespace:MyProject"
mc:Ignorable="d"
x:Name="MyControlRootLayout"
Background="Transparent"
d:DesignHeight="300" d:DesignWidth="300" Cursor="Hand">
<Border x:Name="RootBorder"
Background="{Binding Path=CoreBackground, ElementName=MyControlRootLayout}"
>
</Border>
</UserControl>
그리고 코드에 대한 XAML입니다.