Binding Setting property, but the UI is not updated. Can I debug as part of a project / control?

I have a custom binding control as shown below

<DataTemplate DataType="{x:Type vm:EditorTabViewModel}"> <me:MarkdownEditor Options="{Binding Path=Options, RelativeSource={RelativeSource AncestorType=Window}}" /> </DataTemplate> 

I found that the binding ( Window1.Options ) is installed (after going through the code in debug mode), the markdown editor options (it is supposed to set fonts, colors, etc.) are not installed, or at least the user interface is not Update. I want something to happen with MarkdownEditor.xaml.cs , but with a different (specified) project. How can I verify that the MarkdownEditor.Options parameter is set at a minimum?

I really tested that the side of MarkdownEditor works below

 <Window ...> <Grid> <Button Content="Options" Click="Button_Click" Grid.Row="0" /> <me:MarkdownEditor Options="{Binding Options, RelativeSource={RelativeSource AncestorType=Window}}" Grid.Row="1" /> </Grid> </Window> 

Thus, the difference in the latter is MarkdownEditor only in the Grid in the Window . The only missing is the MarkdownEditor within the TabControl associated with the ObservableCollection<TabViewModel>

Visual Studio Solution Replicating the Problem

I am not very good at things, so the simple project that I created is minus all the unnecessary noises loaded in the media fire so you can see what is wrong.

Video showing problem on Screenr

Simple use of the editor in the window / grid.

binding works fine

Then, when used in conjunction with a TabControl bound to an ObservableCollection<EditorTabViewModel> , the binding works as shown in 2 TextBox es, updating its values. but the editor does not update

+1
wpf binding user-controls
Nov 20 '10 at 6:13
source share
1 answer

After reading Kent Boogaart's answer to this , I think that the right place to change SetValue to SetCurrentValue is not in the CLR Property, but in the MarkDownEditor constructor.

 public MarkdownEditor() { InitializeComponent(); //Options = new MarkdownEditorOptions(); this.SetCurrentValue(OptionsProperty, new MarkdownEditorOptions()); DataContext = this; } 

In fact, this would work just as well without this .SetCurrentValue as well, since the parameters will be set via a binding.

To make sure that Binding was actually overwritten by SetValue, you can add this code to some event for TabUsage (for example, PreviewMouseRightButtonDown for FontSize TextBox) and Binding will start working again.

 private void TextBox_PreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { MarkdownEditor.MarkdownEditor editor = VisualTreeHelpers.GetVisualChild<MarkdownEditor.MarkdownEditor>(this); Binding binding = new Binding(); binding.Path = new PropertyPath("Options"); binding.Source = this; binding.Mode = BindingMode.TwoWay; editor.SetBinding(MarkdownEditor.MarkdownEditor.OptionsProperty, binding); } 
+3
Nov 20 '10 at 9:22
source share



All Articles