Page 1 of 1

SetBinding (Code hinter) funktioniert nicht, textBlock.text wird gelöscht

Posted: 27 Feb 2025, 07:22
by Anonymous
Ich habe ein kleines Testprojekt erstellt, um einfach mein Problem zu veranschaulichen. behind, highlighting information is added to the Inlines of the TextBlock
[*]Because of DataGrid with VirtualizingStackPanel.VirtualizationMode="Recycling" the result of GetBindingExpression(TextBlock.TextProperty) is Null im Ereignis datagrid.onloadingrow aber auch im Ereignis datagridrow.LODED
[*] Ich habe jetzt versucht, den -Bindeln
[*] zurückzusetzen. Bindung.

Ich hoffe, Sie können mir helfen, damit der Text nach dem Einstellen der -Bindung .

Code: Select all



Code hinter

Code: Select all

// Save data for binding
var exp = txtBlock.GetBindingExpression(TextBlock.TextProperty);
txtBlock.Tag = new Tuple(exp.ParentBinding.RelativeSource, exp.ParentBinding.Path)

var inlines = new List();
inlines.Add(new Run(text.Substring(0, 1)));
inlines.Add(new Run(text.Substring(1, 2))
{
Background = filterData.SelectionColor,
Foreground = filterData.ForegroundColor
});
inlines.Add(new Run(text.Substring(3, 1)));

txtBlock.Inlines.Clear();
txtBlock.Inlines.AddRange(inlines);
Im Ereignis

Code: Select all

var tagData = (Tuple) txtBlock.Tag;

var binding = new Binding { RelativeSource = tagData.Item1, Path = tagData.Item2};
txtBlock.SetBinding(TextBlock.TextProperty, binding);    //