wpf checkbox custom attribute binding - wpf

I am working with WPF application. In which I have a scenario where I have to bind one custom attribute to checkbox. Please check the below code-
<comboBox.ItemTemplate>
<DataTemplate>
<checkbox Name="itemCheck" Content =
"{Binding Product}">
cal:Message.Attach ="[Event
Checked] = [Action GetProduct()]"
</checkbox>
</DataTemplate>
</comboBox.ItemTemplate>
As per the above code I wanted to bind one more attribute with checkbox that will be in use at time of calling "GetProduct" function.
I tried to bind that with "Content" attribute of checkbox but I need another attribute or custom attribute by which I can bind some other property, because Context attribute is in use for showing Headers.
Can we add custom attribute in checkbox or is there any in-build attribute by which I can bind some property?

Related

listview checkbox binding wpf MVVM

I am trying to get the bool value of the checkbox present in the Listview. I am binding to a bool public property "Assignm" in the view model. I tried the below binding pattern but the problem is if i select one checkbox it selects all checkboxes and vice versa. I think this is because relativesource is listview and it works on complete listview. I also tried changing the relative source to ListviewItem but that didn't trigger anything. Can someone help me please. Do i need to change something here ?
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding MU_Identifier}" IsChecked="{Binding DataContext.Assignm, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}">
</CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
Because your binding for IsChecked property is Assignm property which seems to be one property of your view model.
If there is a boolean property named Assignm for the data model of the DataSource of ListView, then just change the binding like this: {Binding Assignm}, as Tag property does.
All your items are bounded to a single property, so when one item changes a property in your context it changes on other items.
To provide correct work all your items from ItemsSource should have property IsChecked.
Check this Example

Cannot set value of property on checkbox binding

<CheckBox x:Uid="cbRFEnableManualControl"
Grid.Column="0"
Grid.Row="0"
Name="cbRFEnableManualControl"
VerticalAlignment="Center"
Margin="0,0,0,12"
IsChecked="{Binding RFEnableManualControl, Mode=TwoWay}"
Checked="RFEnableManualControlChanged"
Unchecked="RFEnableManualControlChanged">
<CheckBox.Content x:Uid="EnableManualControlContent">
Enable manual control
</CheckBox.Content>
</CheckBox>
If I check this checkbox then i should enable some controls. I have a property "RFEnableManualControl" in my data model class, based on this value am enabling/disabling the other controls.
Issue is, i have another one button, if i check this checkbox after clicking this button the value is not set for this property. the execution is not going into this property and directly hitting the RFEnableManualControlChanged event.
In this another one button am calling the constructor of this data model class but am not assiging anything to this particular property.

How to update an object's inner property from UI to VM? (WPF MVVM)

I have a property in my ViewModel, I'll call it "Project" which contains several nested lists inside of it. None of such lists has an associated property in the view model since I can show everything in xaml by using triggers and bindings.
My xaml shows the Project hierarchy in a treeview and its details in several views (a content control selects the right view depending on which item is selected on the treeview). One of those "details" is a property for the objects contained in one of the nested lists, I'm showing it in a textbox so the user can edit it, the problem I'm having is I don't see that property updated in the Project property in the VM once I make changes to it in the textbox.
I was told I have to create a property in the VM for that specific object's property I'm trying to edit, I just don't know how since the object is deep inside one of the nested lists of my Project object.
Common mistakes are:
Using OneWay binding mode instead of TwoWay
In XAML:
<TextBox Text="{Binding Path=Name, Mode=TwoWay}" />
Not realizing that the update is not propagated to the VM until after the TextBox lost focus.
this is the default for the TextBox:
<TextBox Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus}" />
You could change it to:
<TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" />

WPF DataGrid binding custom row header give me suggestion

I am trying to do togglebutton visiblity change on true/false properties,
my togglebutton in row header template,
I also create convert for change properties.
Visibility="{Binding Path=col1, Converter={StaticResource ResourceKey=DemoConvertor}}"
refer this like:
https://skydrive.live.com/P.mvc#!/selectembed.aspx/.Public/dgRowToggleButtonSample.zip?ref=11&cid=0c0b4f9d80b744cd&sc=documents

Making use of DataGrid SelectedItem property to control look of TemplateColumn

When creating a custom column design for a Silverlight DataGrid, is there any way to bind or make use of the DataGrid's SelectedItem property?
I wish to display a static element, but have it only visible for the row that is selected.
A simple example of what I'm after:
<data:DataGrid>
<data:DataGrid.Columns>
...
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Selected" Visibility="{IsSelected ? Visible : Collapsed}">
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
...
</data:DataGrid.Columns>
</data:DataGrid>
The column does not need to contain any other elements or bindings.
It does not need to control the Visibility property specifically - any means that hides the element on all rows except the selected row will do.
Can this be done with styles? (Note that there is already one style applied to the DataGrid).
Does RowDetails meet your needs?
Ultimately I made do with a work around - the class used as the ItemSource had a Selected property added which was automatically updated to sync with changes to the list. Then I added a Visiblity property (I could have used a converter as well) to converted the boolean selected to a visibility value, which was used to control the visual appearance of controls in a column of the selected item in the list.

Resources