코드에 문제가 있다고 생각하지 않습니다. 그것은 내 끝 부분에서 완벽하게 작동하는 것 같습니다. xaml과 codebehind 모두에서 코드를 전적으로 시도해 보았습니다.
예상대로 작동하고 바인딩이 완벽합니다.
아래 샘플을 포함 시켰습니다. 확인해 봐. 바인딩은 내 끝에서 완벽하게 작동합니다!
XAML : 뒤에
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:viewModel="clr-namespace:WpfApplication1.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
>
<Grid x:Name="Grid1" />
</Window>
코드 :
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ToggleButton two = new ToggleButton();
two.Content = "Two";
two.Width = 100;
two.Height = 50;
/* Set up ToggleButton here*/
this.Grid1.Children.Add(two);
ToggleButton one = new ToggleButton();
if (one == null) return;
one.Content = "One";
one.Width = 100;
one.Height = 50;
one.Margin = new Thickness(0, 0, 250, 0);
this.Grid1.Children.Add(one);
Binding binding = new Binding("IsChecked");
binding.Source = two;
binding.Mode = BindingMode.TwoWay;
one.SetBinding(ToggleButton.IsCheckedProperty, binding);
/* Add two to the UI */
}
}
}
코드에서 바인딩을 작성하지 마십시오, 그것은 엉망입니다. –
그래서 토글 버튼이 정상적인 토글 버튼의 기능과 반대가되도록하려면? 왜 같은 단추를 사용해야합니까? – Paparazzi
@Paparazzi 그들은 서버의 동일한 객체를 나타내지 만 다른 메뉴의 – KevinA