Is there a concise way to define properties in a ViewModel for data binding in C# WPF? The following property definition is very verbose, especially when there are lots of properties:
private bool mSomeProperty;
public bool SomeProperty
{
get { return this.mSomeProperty; }
set
{
if (value != this.mSomeProperty)
...
Simplified architecture of my Silverlight app:
MainPage; DataContext set to MainViewModel
MainPage has two elements: UserControl and Rectangle
in MainViewModel, I have two properties, UserControlVisible and RectVisible, both of type Visibility, binded to Visibility properties of those two elements in MainPage.XAML
MainViewModel has I...
Background:
I have a List<T> in my ViewModel defined as...
private List<FooBar> _fooBars;
public List<FooBar> FooBars
{
get { return _fooBars; }
set
{
if (value == _fooBars) return;
_fooBars = value;
OnPropertyChanged("FooBars");
}
}
FooBar is defined as...
public class FooBar
{
public st...
I've found view models to be very useful for splitting user interface and business logic code. However, I've also made the experience that for small, simple windows a view model class just adds a lot of additional code, effectively reducing maintainability instead of improving it.
Let me give you a simple, real-world example that I've h...
How can bind an event on a WPF Control to a method on my ViewModel?
I have a ViewModel:
class MyViewModel {
public string MyText { get; set; }
public void MyMouseHandleMethod(object sender, EventArgs e) { }
}
In a DataTemplate I've got:
<TextBlock Text="{Binding Text}">
Now I would like to attach a method on my ViewModel t...
I have been reading about MVVM pattern from various sources like MSDN:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
In that article it says: Unlike the Presenter in MVP, a ViewModel does not need a reference to a view.
If the View (XAML) assumes it's DataContext is the ViewModel then where in the code is the following line:...
I have a View with ViewModel as datacontext ( set in code) . In my view I have a list
<UserControl x:Class="ZPOS.Modules.Menu.Views.DepartmentView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="clr-namespace:Microsoft.Practices.Compo...
I have a button in my ListView group header that performs operations on the group as a whole, and I am having trouble binding the Click event to an ICommand in my view model. I'm using SimpleCommand from C# Disciples if that's any help.
http://marlongrech.wordpress.com/2008/11/26/avoiding-commandbinding-in-the-xaml-code-behind-files/
I...
I have a ViewModel with a State property and a Datatemplate wich contains a simple rectangle with a background brush. Whenever the State of the ViewModel changes I want to trigger an animation that starts with the color the brush currently has and animates it to the new color representing the new state. I have done this with datatriggers...
I am trying to resize a ListView in WPF. I want to figure out how to force a ListView to shrink it's width to only fit the width of it's columns. I have a ListView that I bind using the View property and add some GridViewColumns like so:
<ListView ItemsSource="{Binding MyCollection}">
<ListView.View>...
I've got a datagrid column as below:
<toolkit:DataGridTemplateColumn>
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=LabelName}" Background="{Binding Path=Color}">
<TextBloc...
This may be a bit winded because I am new to wpf. I have created a partial class for an entity in my L2S class that is primarily used for validation. It implements the onchanging and onvalidate methods. I am trying to use the MVVM pattern, and in a window/view I have set the datacontext in the xaml:
<Window.DataContext>
<vm:StartVie...
I have a module in a Prism application and in its initialize method I want to register a presenter instead of a view with a region, i.e. I want to do this:
PSEUDO-CODE:
regionManager.RegisterPresenterWithRegion(
"MainRegion", typeof(Presenters.EditCustomerPresenter));
instead of loading a view like this:
regionManager.RegisterV...
I have a ViewModel that implements IDataErrorInfo and a master-detail-view. How can I trigger the vaildation of the current ViewModel item when the user hits the save button in the detail view and not earlier?
...
Thanks to this question (click me!), I have the Source property of my WebBrowser binding correctly to my ViewModel.
Now I'd like to achieve two more goals:
Get the IsEnabled property of my Back and Forward buttons to correctly bind to the CanGoBack and CanGoForward properties of the WebBrowser.
Figure out how to call the GoForward() a...
How do I bind a view model property to the ListBox.SelectedItem property?
I have created a simple MVVM demo to try to figure this one out. My view model has these properties:
private ObservableCollection<DisneyCharacter> p_DisneyCharacters;
public ObservableCollection<DisneyCharacter> DisneyCharacters
{
get { return p_DisneyCharact...
I have a WPF ItemsControl who's ItemsSource is bound to an observable collection of view models in MVVM. The ItemTemplate is set to the user control that I want. However, there are instances when I would like another control instead of the one specified in XAML.
How can I easily do this?
...
I'm new to WPF and MVVM. I am working with a team on LoB application. We would like to have a dynamic menu control, which creates the menu based on the logged in user profile. In previous development scenarios (namely ASP.NET) we use to iterate through data which describes collection and generate MenuItem dynamically. In MVVM how would I...
Hi,
I'm asking myself how to apply MVVM in the following scenario correctly:
Let's assume I have simple Master-Detail data, like a person with 0-n addresses.
The addresses should be displayed in a ListBox and the user should be able to trigger certian actions for each address.
So what I did is to create a VM which returns the person mo...
In my ViewModel I have a list of items that I would like a grid in my view to bind to (the items will be the grids children). The list is a list of view models for the items.
How do you bind a grid to the list (I can access .children in code but not xaml)?
Also, how do you specify the data template (another xaml file) for the view mode...