ivalueconverter

Binding ObservableCollection<> to a TextBox

こ雲淡風輕ζ 提交于 2019-12-01 15:29:22
问题 I have data comming back from web service in the form of a ObservableCollection<string> I want to bind the collection to a read-only TextBox so that the user can select and copy the data to the clipboard. To get the collection bound to the Text property of the TextBox I created IValueConverter which converts the collection to a text string. This seems to work except that it only works once, it is as if the binding does not recognize subsequent changes to the Observable collection. Here is a

How can I set a dependency property on a static resource?

五迷三道 提交于 2019-12-01 05:40:13
问题 I'm trying to get around the fact that I can't specify a dynamic value for ConverterParameter . See my other question for why I need to bind a dynamic value to ConverterParameter - I don't like the solutions currently posted because they all require what I feel should be unnecessary changes to my View Model. To attempt to solve this, I have created a custom converter, and exposed a dependency property on that converter: public class InstanceToBooleanConverter : DependencyObject,

Using Unity to inject objects into IValueConverter instance

不羁岁月 提交于 2019-12-01 04:27:20
I have an instance of IValueConverter in a Silverlight 5 project, which converts custom data into different colors. I need to read the actual color values from a database (as these can be edited by the user). Since Silverlight uses asynchronous calls to load the data through Entity Framework from the database, I created a simple repository, which holds the values from the db. The interface: public interface IConfigurationsRepository { string this[string key] { get; } } The implementation: public class ConfigurationRepository : IConfigurationsRepository { private readonly TdTerminalService

Get the Source value in ConvertBack() method for IValueConverter implementation in WPF binding

妖精的绣舞 提交于 2019-11-30 13:55:33
I am binding a dependency property to textboxex in WPF. The property is a string that has some values separated by '/' (example: "1/2/3/4" ). I need to bind individual values to separate textboxes which is fine with following implementation of Convert() method: public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture) { if (!string.IsNullOrEmpty(value as string)) { String[] data = (value as string).Split('/'); return data[Int16.Parse(parameter as string)]; } return String.Empty; } And I am using the ConverterParameter in xaml to specify the

Can I pass entire UI element into a IValueConverter?

拜拜、爱过 提交于 2019-11-30 09:58:45
问题 <DataTemplate> <StackPanel Orientation="Vertical" Name="AddressStackPanel" > <ComboBox Name="ComboBox" ItemsSource="{Binding Path=MatchedAddressList}" DisplayMemberPath="Address" SelectedIndex="0" SelectionChanged="ComboBox_SelectionChanged"/> <TextBlock Name="InputtedAddress" Text="{Binding Path=InputtedAddress}" Foreground={Hopefully pass the UI element to the dataconverter } /> </StackPanel> </DataTemplate> The ComboBox has addresses matched by from a geodatabase with the highest scoring

The point of ValueConversionAttribute class?

帅比萌擦擦* 提交于 2019-11-30 02:44:09
What is the point of this attribute? After adding it I still need to make a cast on value object. [ValueConversion(sourceType: typeof(double), targetType: typeof(string))] public class SpeedConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var speed = (double)value; Is it only for code readability? Because when I change a binding's path to a String in xaml, Visual Studio doesn't give a warning about incorrect type and exception is thrown only when casting, so it doesn't mean a thing even in early error catching while

Pass value of a field to Silverlight ConverterParameter

拜拜、爱过 提交于 2019-11-30 01:51:26
问题 I'm writing my very first Silverlight app. I have a datagrid with a column that has two labels, for the labels, i am using an IValueConverter to conditionally format the data. The label's "Content" is set as such: Content="{Binding HomeScore, Converter={StaticResource fmtshs}}" and Content="{Binding AwayScore, Converter={StaticResource fmtshs}}" The Convert method of my IValueConverter is such: Public Function Convert( ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As

how to pass an integer as ConverterParameter?

做~自己de王妃 提交于 2019-11-29 20:32:09
I am trying to bind to an integer property: <RadioButton Content="None" IsChecked="{Binding MyProperty, Converter={StaticResource IntToBoolConverter}, ConverterParameter=0}" /> and my converter is: [ValueConversion(typeof(int), typeof(bool))] public class IntToBoolConverter : IValueConverter { public object Convert(object value, Type t, object parameter, CultureInfo culture) { return value.Equals(parameter); } public object ConvertBack(object value, Type t, object parameter, CultureInfo culture) { return value.Equals(false) ? DependencyProperty.UnsetValue : parameter; } } the problem is that

Get the Source value in ConvertBack() method for IValueConverter implementation in WPF binding

人盡茶涼 提交于 2019-11-29 19:35:12
问题 I am binding a dependency property to textboxex in WPF. The property is a string that has some values separated by '/' (example: "1/2/3/4" ). I need to bind individual values to separate textboxes which is fine with following implementation of Convert() method: public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture) { if (!string.IsNullOrEmpty(value as string)) { String[] data = (value as string).Split('/'); return data[Int16.Parse

Can I pass entire UI element into a IValueConverter?

扶醉桌前 提交于 2019-11-29 18:08:26
<DataTemplate> <StackPanel Orientation="Vertical" Name="AddressStackPanel" > <ComboBox Name="ComboBox" ItemsSource="{Binding Path=MatchedAddressList}" DisplayMemberPath="Address" SelectedIndex="0" SelectionChanged="ComboBox_SelectionChanged"/> <TextBlock Name="InputtedAddress" Text="{Binding Path=InputtedAddress}" Foreground={Hopefully pass the UI element to the dataconverter } /> </StackPanel> </DataTemplate> The ComboBox has addresses matched by from a geodatabase with the highest scoring value selected. The Textblock has the user-inputted address that was used for matching. If the address