안녕하세요 저는 사용자 컨트롤 속성을 바인딩하려고하지만 지금까지 성공하지 못했습니다. 아래는 제 코드입니다.wpf usercontrol 속성을 바인딩하는 방법
<UserControl x:Class="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"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="120"
x:Name="uc"
Background="Transparent">
<Grid>
<Viewbox>
......
<CheckBox Name="Start" Visibility="Hidden" IsChecked="{Binding Path=Animation, ElementName=uc, Mode=TwoWay}"/>
.......
</Viewbox>
</Grid>
</UserControl>
사용자 제어 코드가 뒤 따른다.
public partial class MyControl: UserControl
{
public static readonly DependencyProperty AnimationProperty = DependencyProperty.Register("Animation", typeof(bool), typeof(CircularProgressBar));
public bool Animation
{
get { return (bool)GetValue(AnimationProperty); }
set
{
SetValue(AnimationProperty, value);
}
}
public MyControl()
{
InitializeComponent();
//(this.Content as FrameworkElement).DataContext = this;
}
}
보기 코드
<local:MyControl x:Name="cpb" Animation="{Binding CpbIsEnabled, Mode=TwoWay}" />
보기 모델 코드
private bool cpbEnabled;
public bool CpbIsEnabled
{
get { return cpbEnabled; }
set { cpbEnabled = value; OnPropertyChanged("CpbIsEnabled"); }
}
public ICommand ShowSelFlagCommand
{
get
{
return showSelFlagCommand ?? (showSelFlagCommand = new DelegateCommand(() =>
{
if (CpbIsEnabled) { CpbIsEnabled = false; }
else { CpbIsEnabled = true; }
}
));
}
}
나는 뒤에 사용자 제어 코드에서 애니메이션 속성 설정 방법에 브레이크 포인트를 넣어. 그러나 뷰 모델에서 ICOmmand가 실행되면 중단 점에 도달하지 않습니다. 즉, 애니메이션 속성은 바인딩에 의해 설정되지 않습니다.
누군가 내가 놓친 내용을 말해 줄 수 있습니까?
덕분에,
애니메이션 속성이 설정 방법은 바인딩에 의해 호출되지 않습니다. 이 속성은 코드를 가져 오거나 설정할 때만 사용됩니다. –
바인딩에서 애니메이션 속성을 설정하지 않았습니다. 어떻게 작동시킬 수 있습니까? – Shawn
표준 속성 구문을 DependencyProperty의 래퍼로 사용한다고 생각합니다. getter는 괜찮지 만 setter는 SetValue (AnimationProperty, value) 만 호출해야합니다. – jhenninger