ivalueconverter

Odd behavior when trying to change a bound RadioButton in WPF

陌路散爱 提交于 2019-12-02 12:54:09
问题 I've bound two radio buttons in my Child window to an Enum in my ViewModel which is constructed in the Main window. The binding works as expected but I have noticed a very odd behavior which I can't solve. I have provided all the code here so you can reconstruct the problem easily for yourself. Here are the steps to see this odd behavior: Click on the button in the MainWindow The ChildWindow opens and the RadioButton is set to User Choose Automatic and then Choose User again Close the

Padding a numeric display in WPF

时光总嘲笑我的痴心妄想 提交于 2019-12-02 12:16:33
问题 I've got a position readout that's very simple -- it's just a TextBlock with a Style applied to it. In that Style, I just set it like so (there are more properties than this, but I took them out for conciseness): <Style x:Key="NumberStyle" TargetType="{x:Type TextBlock}"> <Setter Property="TextAlignment" Value="Center" /> </Style> Now, I have one display that uses this style, and it will display a number from 0.0 to 30000.0. The problem is that since I'm centering the text, the number (if

Creating a Converter to take an ID and create an Image in Silverlight

强颜欢笑 提交于 2019-12-02 08:19:52
I am using a WCF weather service and receiving weather information like ID, Description, and Images. It returns like this: <WeatherDescription> <WeatherID>1</WeatherID> <Description>Thunder Storms</Description> <PictureURL> http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif </PictureURL> </WeatherDescription> Now in the XAML I am showing my data in a dataGrid as so: <sdk:DataGridTextColumn Header="ID" Binding="{Binding WeatherID}" /> The above binding is to another function of the service that returns a 7 day forecast but returns the same weather ID that works with the weather description.

Why isn't a property in my ViewModel updated when DataGrid changes?

若如初见. 提交于 2019-12-02 07:45:45
I'm trying to create a UserControl, that will let me edit a Dictionary of type Dictionary<string,string> in a grid (just editing entries so far, not adding or deleting). Whenever I bind the DataGrid to a Dictionary it shows the grid as read only, so I decieded to create a value converter, that would convert it to an ObservableCollection<DictionaryEntry> where DictionaryEntry is just a class with two properties Key , and Value . This works for display the dictionary in the grid, but now when I make changes to the grid, my dictionary is not being updated. I'm unsure why. I think it's either a

Dynamic image source binding in silverlight

好久不见. 提交于 2019-12-02 04:37:11
问题 I want to set an image's source according to its DataContext in a ChildWindow . Here is the XAML file: <controls:ChildWindow x:Class="CEM.Controls.DialogWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Title="{Binding Title}"> ... <Image x:Name="DialogIcon"></Image> ... </controls:ChildWindow> It's working fine if I override

Padding a numeric display in WPF

主宰稳场 提交于 2019-12-02 04:07:10
I've got a position readout that's very simple -- it's just a TextBlock with a Style applied to it. In that Style, I just set it like so (there are more properties than this, but I took them out for conciseness): <Style x:Key="NumberStyle" TargetType="{x:Type TextBlock}"> <Setter Property="TextAlignment" Value="Center" /> </Style> Now, I have one display that uses this style, and it will display a number from 0.0 to 30000.0. The problem is that since I'm centering the text, the number (if changing rapidly) jumps all over the place and it's a little disturbing. I'd like to format my string so

Refreshing a binding that uses a value converter

牧云@^-^@ 提交于 2019-12-01 20:50:01
I have a WPF UI that is bound to an object. I'm using a ValueConverter to convert a property to a specific image by a business rule: public class ProposalStateImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var proposal = value as Proposal; var basePath = "pack://application:,,,/ePub.Content;component/Images/General/Flag_{0}.png"; string imagePath; if(proposal.Invoice != null) { imagePath = string.Format(basePath, "Good"); } else { imagePath = string.Format(basePath, "Warning"); } var uri = new Uri(imagePath); var

Getting index of an item in an ObservableCollection inside the item

一曲冷凌霜 提交于 2019-12-01 17:49:47
I'd like to be able to display an index value from within a DataTemplate, but I don't want the data to be persisted or backed by the model or viewmodel. In other words, if the order of the items in the OC changes, I don't want to have to recalculate the indexes. The value should be intrinsically tied to the underlying index in the OC. It is okay if the index is 0-based (in fact, I'd expect it). One method that others have used is the AlternationIndex AP, but this has its own pitfalls for certain situations. One last thought: I can't help but think that a converter is going to be helpful in a

Getting index of an item in an ObservableCollection inside the item

ⅰ亾dé卋堺 提交于 2019-12-01 17:19:30
问题 I'd like to be able to display an index value from within a DataTemplate, but I don't want the data to be persisted or backed by the model or viewmodel. In other words, if the order of the items in the OC changes, I don't want to have to recalculate the indexes. The value should be intrinsically tied to the underlying index in the OC. It is okay if the index is 0-based (in fact, I'd expect it). One method that others have used is the AlternationIndex AP, but this has its own pitfalls for

Binding ObservableCollection<> to a TextBox

蹲街弑〆低调 提交于 2019-12-01 15:49:00
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 simple application that reproduces the problem, just to confirm the binding is working correctly I also