C#从textbox的绑定列转换回JObject
再见! 我不擅长wpf和绑定,我需要你的帮助。我已经将Json对象(JObject)绑定到TextBox的一列C#从textbox的绑定列转换回JObject,c#,json,wpf,binding,C#,Json,Wpf,Binding,再见! 我不擅长wpf和绑定,我需要你的帮助。我已经将Json对象(JObject)绑定到TextBox的一列 <TextBox Width="250" Text="{Binding Path=Property, Converter={StaticResource jPropertyConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 我可以更改此JObject树的“叶子”值,如下所示: (val
<TextBox Width="250" Text="{Binding Path=Property, Converter={StaticResource jPropertyConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
我可以更改此JObject树的“叶子”值,如下所示:
(valoreProperty as JValue).Value = "Hello!";
如何在转换回中更改此JObject树的“叶子”?
对不起我的英语。
谢谢,再见
编辑:
谢谢dbc!它的工作,非常感谢
现在我需要在另一列中显示文本框内的每个长度值,显然,如果我更改文本框中的值,相对长度值也会更改
我试过:
<DataGridTextColumn Header="Lunghezza2" IsReadOnly="True" Width="50" Binding="{Binding Path=Property.Value.Value.toString().Length, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" />
但是当我更改文本框的值时,每次尝试都不起作用,有什么提示吗?
再次感谢 为此,您不需要转换器。假设您的
属性
属性返回一个JProperty
,您可以直接绑定到JProperty.Value.Value
<TextBox Name="PropertyTextBox"
Text="{Binding Path=Property.Value.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
使用转换器
public class IsSimpleJPropertyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is JProperty)
{
JToken jValue = (value as JProperty).Value;
if (jValue is JValue)
return true;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
问题不清楚,你能用一种更简单的方式解释一下吗。第二部分向上4编辑:
<TextBox Name="PropertyTextBox"
Text="{Binding Path=Property.Value.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox Name="PropertyTextBox"
Text="{Binding Path=Property.Value.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Path=Property, Converter={StaticResource IsSimpleJPropertyConverter}, Mode=OneWay}"
/>
public class IsSimpleJPropertyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is JProperty)
{
JToken jValue = (value as JProperty).Value;
if (jValue is JValue)
return true;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}