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
Related
I've got and update form that I've bound to a datatable in WPF. I've got one Field in the Record STATUS that has only 3 possibilitye A for Archived, C for Current or D for Draft. I would like to put a Combobox on the form that would show the text for the selected record and can Update the database if the user wants to change the status. I have searched all over the web and have not found an easy way to do this. Can someone out there give me a suggestion as to where to start?
I didn't get any responses. Reading it I didn't phrase the question very well. But I found an answer to my question in another post.
<ComboBox SelectedValuePath="Tag" SelectedValue="{Binding Path=STATUS}">
<ComboBoxItem Tag="A">Archived</ComboBoxItem>
<ComboBoxItem Tag="C">Current</ComboBoxItem>
<ComboBoxItem Tag="D">Draft</ComboBoxItem>
</ComboBox>
If anybody else is having this problem this might help.
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>.
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();
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.
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}}" />