作爲示例silverlight Textbox在底層集合的相應屬性發生更改時未更新
我有2個文本框。兩個文本框的文本都綁定到類名{String fullname,String funnyName};他們不是直接綁定,而是通過轉換器
他們正在實施INotifyChanged
和綁定DataContext
是ObservableCollection
和所有其他標準的東西。
此模板綁定,因此我有一個2個文本框和列表框有10行 的問題是:
,當我在文本框中輸入1更改全名,我去更改的funnyname綁定的集合。
這不會立即反映到GUI上。
我該如何做到這一點?我不想更新整個列表框,我不想直接將其綁定到我的課程中的另一個屬性,而是通過轉換器。當屬性從「TOm」改變爲「dick」時,轉換器不會被調用,即只有第一次調用轉換器。接下來每當有些財產發生變化時,
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("FunnyName"));
被調用,轉換器不被調用。
增加了原代碼
集合類
public class VariableData : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
字符串_Source;
/// <summary>
/// Gets or sets the source.
/// </summary>
/// <value>
/// The source.
/// </value>
public String Source
{
get { return _Source; }
set
{
_Source = value; if (this.PropertyChanged != null)
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Source"));
}
}
}
結合
<TextBox Name="textBoxFileLocation"
Text="{Binding Converter={StaticResource mapTypeToDataConverter}, ConverterParameter=41}"
Margin="5,5,5,5" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2">
</TextBox>
轉換器
public class MapTypeToDataConverter : IValueConverter
{
#region IValueConverter Members
/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <param name="value">The source data being passed to the target.</param>
/// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
/// <param name="parameter">An optional parameter to be used in the converter logic.</param>
/// <param name="culture">The culture of the conversion.</param>
/// <returns>
/// The value to be passed to the target dependency property.
/// </returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return "";
VariableData cus = null;
try
{
cus = (VariableData)value;
}
catch (Exception e3)
{
return null;
}
if (cus == null)
return "";
int temp = int.Parse(parameter.ToString());
int mapType = temp/10;
int whatToreturn = temp % 10;
if (mapType != cus.MappingType)
{
if (whatToreturn == 3)
return false;
else
return "";
}
switch (whatToreturn)
{
case 1:
return cus.Source;
break;
case 2:
return cus.Query;
break;
case 3:
if (cus.Source != null && cus.Source.Length > 0)
return true;
else
return false;
}
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (int)value;
}
#endregion IValueConverter Members
}
no ..仍然沒有兩個waybinding ...說ter是我的datacontext colelction中的10個對象...我編輯第1行對象屬性,然後單擊提交..點擊處理程序去更新行1對象屬性,也第5行和第10行對象屬性...我希望gui反映對第5行和第10行進行的更改...並且請注意,所有文本屬性都綁定到轉換器.... – pskk 2011-05-13 21:03:48
@pskk - 你能編輯你的xaml進入你的問題(顯示你的收藏的位)。我無法想象這個問題。 – ChrisF 2011-05-13 21:05:57
..用代碼更新了問題......謝謝 – pskk 2011-05-13 21:14:22