programmatically binding images to silverlight grid cell based on condition [closed] - silverlight

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
how can i programmatically binding images to silverlight datagrid cell of a particular column based on the datasource values

Use an implementation of IValueConverter that I blog about here. I'll assume for the moment (your question lacks detail so I'll make some up) that you have some kind of property that exposes an enum of a finite set of states.
In your case the value converter will contain a ResourceDictionary of BitmapImage entries:-
<local:StringToObjectConverter x:Key="StatusToIcon">
<ResourceDictionary>
<BitmapImage UriSource="/Assets/State1.png" x:Key="State1" />
<BitmapImage UriSource="/Assets/State2.png" x:Key="State2" />
<BitmapImage UriSource="/Assets/UnknownState.png" x:Key="__default__" />
</ResourceDictionary>
</local:StringToObjectConverter>
In the template for your cell you would use:-
<Image Source="{Binding State, Converter={StaticResource StatusToIcon}}" />

Related

XAML: how to access items from resources.resx [duplicate]

This question already has answers here:
How to get a Uri of the image stored in the resources
(2 answers)
Assign BitmapImage from Resources.resx to Image.Source?
(1 answer)
Not able to reference Image source with relative path in xaml
(3 answers)
Closed 3 years ago.
I'm learing WPF and XAML. I'm trying to show an image loaded from resources.resx.
For this, I've added an existing image to resources.resx. The identifier of the image is GoogleLogo. If I open Resources.ResX is can see that the image indeed is present in the resource file.
Now I want a window that shows this image in a Grid. The XAML is like:
<Window x:Class="WpfDemo.MainWindow"
xmlns=...
Title="Show Google Logo" Height="160" Width="800">
<Grid>
<Image Source="???"/>
</Grid>
</Window>
How to refer to the Source in resources.ResX? What to type instead of ???

How to populate wpf combobox in xaml [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need to populate wpf combobox with fixed collection of strings (for example months from january to december).
In namespace add declaration:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
then add combobox where appropriate:
<ComboBox>
<sys:String>January</sys:String>
<sys:String>February</sys:String>
<sys:String>March</sys:String>
...
<sys:String>December</sys:String>
</ComboBox>
Like this?
<ComboBox >
<ComboBoxItem Content="January"></ComboBoxItem>
<ComboBoxItem Content="February"></ComboBoxItem>
<ComboBoxItem Content="March"></ComboBoxItem>
<ComboBoxItem Content="April"></ComboBoxItem>
// .... and so on....
</ComboBox>
You should bind the ItemsSource of the combo box to the property of the List<string>.

XAML enlighten me with this binding commands [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
what are these? I am confused with the extra properties in "Binding"
{Binding Path=Customers, Source={StaticResource customerVM}, Mode=TwoWay}
{Binding Path=GetCustomersByNameCommand, Source={StaticResource customerVM}}
{Binding Path=Text, ElementName=tbName}
{Binding Path=DataContext, ElementName=LayoutRoot}
{Binding Path=TotalIncome, Mode=OneTime}
and more of those. What are those? I mean, where are they getting the Mode, Path, etc.. I don't understand.
The only thing I can understand is
{Binding ProperyName}
{StaticResource Anythinghere}
Binding in XAML can be specified in many ways.
The simplest (shortcut) is
{Binding PropertyName}
This is equivalent to
{Binding Path=PropertyName}
This is equivalent to:
<Binding Path="PropertyName" />
Binding is actually a class with various properties such as Path, Source, Mode, etc.
More details on how to bind data in WPF can be found at : http://msdn.microsoft.com/en-us/magazine/cc163299.aspx#S2

Find control in templated WPF datagrid [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
get value of checkbox from datagrid? C#
I am trying to find a control inside the selected row in a templated DataGrid.
<DataGridTemplateColumn Header="Local">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkImport" IsChecked="{Binding IsLocalized}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
I am trying the following code:
var selectedRow = (DataGridRow) gridFileScan.ItemContainerGenerator.ContainerFromItem(gridFileScan.SelectedItem);
CheckBox chkImport = FindVisualChild<CheckBox>(selectedRow);
but chkImport is always null. Any ideas ??
When you debug you should be able to see the method recurse the VisualTree.
You can see the Visual Tree by using the Visual Tree Visualizer
The implementation of FindVisualChild might be flawed or the VisualTree doesn't look like what you expect.
Found it. I just had to call this method after modifying ItemsSource:
gridFileScan.UpdateLayout();

Neptune2 [just came from Mars] [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
well , seriously guys i got sick of WPF errors and hard handling , look i got many buttons are dsigned to represent rooms and i want to bind into a tooltip to get occupier name and informations from database .
i cant find how to do it.
Thanks
Build a RoomViewModel class that exposes Description, IsAvailable, OtherInformation, and other properties and implements INotifyPropertyChanged. How you populate these properties is up to your application.
Build a RoomsViewModel class that exposes an ObservableCollection<RoomViewModel> named Rooms.
Create DataTemplates for the RoomViewModel and RoomsViewModel classes (see below).
Create an instance of the RoomsViewModel class and populate its Rooms collection.
Create a ContentPresenter and set its Content property to the instance of your RoomsViewModel class.
Typical data templates might look like this:
<DataTemplate x:Type="{local:RoomsViewModel}">
<ItemsControl ItemsSource="{Binding Rooms}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
<DataTemplate x:Type="{local:RoomViewModel}">
<Button
Margin="10"
IsEnabled="{Binding IsAvailable}"
ToolTip="{Binding OtherInformation}"
Content="{Binding Description}"/>
</DataTemplate>
Future enhancements:
Try using a UniformGrid instead of a WrapPanel.
Read Josh Smith's article Using RoutedCommands with a ViewModel in WPF and use the techniques described there to create a ReserveRoomCommand property on the RoomViewModel. Set the CommandBinding in the RoomViewModel data template to {Binding ReserveRoomCommand}. Note that once you do this, you'll remove the binding to IsEnabled, because the command binding will enable and disable the button automatically.
If you are going to need to reuse this UI, move the data templates and content presenter into a UserControl.

Resources