Greetings,
I got a custom control which displays the weight of a Vertex in a circle.
I build this with a boarder which contains a stackpanel. This stackpanel keeps the textblock. The TextBlock.Text property is binding to the Vertex.Weight property. The weight and the binding is displayed correctly.
But I also wanted to make the weight of the vertex editable. So I added a TextBox to the StackPanel which also binds to the Vertex.Weight.
The TextBox will be only displayed when the custom control is focused (The TextBlock visiblity will then be changed to collapsed).
The xaml code looks something similiar to this:
<!-- ControlTemplate of VertexControl --><Style TargetType="{x:Type local:VertexControl}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:VertexControl}"><Grid><Border CornerRadius="50" Background="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"><StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock Text="{Binding Mode=TwoWay,Path=Vertex.Weighted,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}}}" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock.Style><Style TargetType="{x:Type TextBlock}"><Style.Triggers><DataTrigger Binding="{Binding Path=IsFocused,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}},UpdateSourceTrigger=PropertyChanged}" Value="False"><Setter Property="Visibility" Value="Visible" /></DataTrigger><DataTrigger Binding="{Binding Path=IsFocused,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}},UpdateSourceTrigger=PropertyChanged}" Value="True"><Setter Property="FontWeight" Value="Bold" /></DataTrigger><DataTrigger Binding="{Binding Path=IsFocused,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}},UpdateSourceTrigger=PropertyChanged}" Value="True"><Setter Property="Visibility" Value="Collapsed" /></DataTrigger></Style.Triggers></Style></TextBlock.Style></TextBlock><TextBox Text="{Binding Mode=TwoWay,Path=Vertex.Weighted,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}} ,Converter={x:Static local:VertexControl.IntToStringConverter}}"><TextBox.Style><Style TargetType="{x:Type TextBox}"><Setter Property="Width" Value="35" /><Style.Triggers><DataTrigger Binding="{Binding Path=IsFocused,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}},UpdateSourceTrigger=PropertyChanged}" Value="True"><Setter Property="Visibility" Value="Visible" /></DataTrigger><DataTrigger Binding="{Binding Path=IsFocused,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:VertexControl}},UpdateSourceTrigger=PropertyChanged}" Value="False"><Setter Property="Visibility" Value="Collapsed" /></DataTrigger></Style.Triggers></Style></TextBox.Style></TextBox></StackPanel></Border></Grid></ControlTemplate></Setter.Value></Setter></Style>
As you can see the weight property type is an Int. So I added a Converter. I'm unable to select or edit the TextBox.Text content. When I add a breakpoint to the IntToString converter in the ConvertBack method or in the setter of the weight property but it never hits.
Has someone an idea why I can't change the property values of TextBox.Text?
greetings