private void AddCheckBoxControls(ToolbarInfo info) { var check = new ToggleSwitch { Content = IoC.Kernel.Get<IResourceHelper>().ReadResource(info.Text), Tag = info.Text, IsChecked = info.Value }; var label = new Label { VerticalAlignment = VerticalAlignment.Center, Content = check }; if (!string.IsNullOrWhiteSpace(info.Command)) { var checkBoxBinding = new Binding("DataContext." + info.Command) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(MainWindow), 1), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; check.SetBinding(ToggleSwitch.IsCheckedProperty, checkBoxBinding); } Items.Add(label); }
private void AddButtonControls(ToolbarInfo info) { var image = new Image { Source = new BitmapImage(new Uri(info.Image, UriKind.Relative)) }; var button = new Button { Content = image, ToolTip = IoC.Kernel.Get<IResourceHelper>().ReadResource(info.Text) }; var binding = new Binding("DataContext." + info.Command) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(BaseWindow), 1), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; button.SetBinding(Button.CommandProperty, binding); Items.Add(button); }