ivalueconverter

IValueConverter executes more times than expected

安稳与你 提交于 2020-01-06 20:05:47
问题 I have a converter that takes the text from a TextBlock that makes up a DataGridCell and converts it to a red or black brush depending if the value is negative or positive. However the converter executes more times than there are items in the datasource of the grid. For example if I simply bind a collection that contains 1 object, the converter executes 2 times. The first time the value parameter is an empty string, the second time it actually contains the value that I would expect. If I add

IValueConverter executes more times than expected

让人想犯罪 __ 提交于 2020-01-06 20:03:40
问题 I have a converter that takes the text from a TextBlock that makes up a DataGridCell and converts it to a red or black brush depending if the value is negative or positive. However the converter executes more times than there are items in the datasource of the grid. For example if I simply bind a collection that contains 1 object, the converter executes 2 times. The first time the value parameter is an empty string, the second time it actually contains the value that I would expect. If I add

MVVM IValueConverter Convert method getting empty string argument when expecting a float

倾然丶 夕夏残阳落幕 提交于 2020-01-02 19:52:28
问题 This may get a tad long, but here goes. I have created a small, wizard-style sample app using the MVVM pattern (basically a dumbed-down version of the code in my "real" app). In this app, the main window moves from through a List<..> of view models, with each view model displaying its associated view. I have 2 view model classes that are essentially identical, and they display the same view. On the view is a combo box, populated with an array of float. The SelectedItem is bound to a float

Null To Boolean IValueConverter not working

僤鯓⒐⒋嵵緔 提交于 2020-01-02 02:17:12
问题 How do I use an IValueConverter to convert nulls into booleans? I'm using wpf to try to display a bunch of boolean values (in checkboxes). When a new record is created, these values are null, and appear as 'indeterminate' in the checkboxes. I want the nulls to appear and save as 'false' values. I tried to create a NullToBoolean converter that takes null values from the database and displays them as false, and then saves them as false when the user hits save. (Essentially, I'm trying to avoid

refreshing Value Converter on INotifyPropertyChanged

六月ゝ 毕业季﹏ 提交于 2019-12-30 13:39:30
问题 I know there are some similar topics here but I couldn't get any answer from them. I have to update background of a grid to either an image or a colour in my Windows Phone 7 app. I do this using my value converter , it works fine but I'd have to reload the collection so it updates the colour or image. <Grid Background="{Binding Converter={StaticResource ImageConverter}}" Width="125" Height="125" Margin="6"> The converter receives the object then gets the color and image from it, here is the

Silverlight ComboBox binding with value converter

守給你的承諾、 提交于 2019-12-25 08:52:14
问题 I'm attempting to convert the displayed value of a combobox by using its binding as a key to look for the value I would like to display. I can't seem to get it to work. The datacontext of my user control is MyObject. MyObject has a property "MasterDrawerId", which is the Id of "MyReferencedObject". Elsewhere in my application, accessible through a static property of my App.xaml.cs is a collection of "MyOtherObjects". "MyReferencedObject" has a foreign key relationship with the Id of

Does WPF have a set of default binding converters available?

依然范特西╮ 提交于 2019-12-25 07:58:57
问题 When creating WPF user controls I often find myself creating small converter classes when binding values. Often you need to do similar conversions, and it made me wonder whether I might be missing some existing available implementations. Does the .NET library contain any implementations of IValueConverter or IMultiValueConverter? Has there been any attempt made to create a library of reusable value converters? 回答1: There are not many built-in, public are: BooleanToVisibilityConverter

Issue in chaining IValueConvertes in WPF becauase of target type

北城以北 提交于 2019-12-25 00:34:25
问题 I was trying to chain converters as Town's answer in Is there a way to chain multiple value converters in XAML?? I like to make individual converters more strict by having targetType check as well :- if (targetType != typeof(bool)) throw new InvalidOperationException("The target must be a boolean"); But the chain fails as the end target type is different from the target at each stage. I can remove the type check to make less strict as given in most of examples on SO, but I would prefer a

How can i bind a border visibility to the visibility of containing children objects

笑着哭i 提交于 2019-12-24 10:38:16
问题 I have this kind of code below, how can I bind the visibility of the Border to the visibility of all the labels? Of course the number of rows and labels is not fixed. <Border BorderBrush=Black BorderThickness="1,1,1,1"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Label DataContext="{Binding MyObject[1]}" Content="{Binding MyText}" Visibility="{Binding

IValueConverter not getting invoked in some scenarios

爷,独闯天下 提交于 2019-12-24 08:16:11
问题 I am using a collection of texts fetched from a web service, which should be used for a variety of controls. The easiest and most dynamic way to do this, in my opinion, is to use an IValueConverter to get the given text as follows: public class StaticTextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter != null && parameter is string) { return App.StaticTexts.Items.SingleOrDefault(t => t.Name.Equals