.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Closing ChildWindow In MVVM by Using Attached Property

Posted By: Asim Sajjad     Posted Date: June 19, 2011    Points: 2   Category :Silverlight
 
In this post I will show you how to close the ChildWindow of Silverlight using Attached property in MVVM. Let us start with the example code. For this example I have created Silverlight project of template "Silverlight Navigation with Accent Color" application. I have added new ChildWindow in the view folder with the name UserInputForm and then UserInputFormViewModel in the ViewModel folder which is the used to set as the DataContext of the UserInputForm.


View Complete Post


More Related Resource Links

Setting an attached property by a Setter element?

  
I have the fragment below as contents of a <Grid> element. The idea is that if the checkbox is checked the <TreeView> element should only span one instead of two columns. When I check the checkbox the background of the treeview turns red, but the treeview continues to span 2 instead of 1 column. It's a bit like the attached property Grid.ColumnSpan does not get assigned by the <Setter Property="Grid.ColumnSpan" Value="1"/> at all. What should I do in order to achieve what I want?Best regards,Henrik Dahl   <TreeView    x:Name="Blas"    ItemsSource="{Binding Path=BlasRoot.Children}" d:LayoutOverrides="Width" Margin="0,0,0,8" Grid.Column="0" Grid.ColumnSpan="2">    <TreeView.Style>       <Style>          <Style.Triggers> <DataTrigger Binding="{Binding ElementName=chkPosition, Path=IsChecked}" Value="True">    <Setter Property="Grid.ColumnSpan" Value="1"/>    <Setter Property="TreeView.Background" Value="Red"/> </DataTrigger>          </Style.Triggers>       </Style>    </TreeView.Style> </TreeView> <CheckBox HorizontalAlignment="Left" Margin="-50,0,0,0" x:Name="chkPosition" VerticalAlignment="Top" Content="

How do I automaticaly change one property based on another with MVVM?

  

Hi

I have a grid connected to a ViewModel class with two properties, public Address SelectedAddress and public ObservableCollection<Address> Addresses.

Address has, among other things, int? PersonID and int? CompanyID. My validation code in the Model checks that one of them is filled, but not both.

How do I set up code in the grid or ViewModel so that whenever PersonID is filled, CompanyID is automatically set to null, and the other way?

TIA

Dennis


Attached Property

  

I am working a project that has several different controls that I am trying to use an attached property to dictate whether or not to perform a recalculation operation if changed.  I am using what I thought was the standard pattern for the creating of an AP.

    public class RecalcProperty : DependencyObject
    {
        public static readonly DependencyProperty PerformRecalcProperty = DependencyProperty.RegisterAttached(
          "PerformRecalc",
          typeof(Boolean),
          typeof(RecalcProperty),
          new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None)
        );
        public static void SetPerformRecalc(UIElement element, Boolean value)
        {
            element.SetValue(PerformRecalcProperty, value);
        }

        public static Boolean GetPerformRecalc(UIElement element)

Using an argument in an attached property

  

Hi,

I've written a workflow level ErrorMessage as an attached property on the root workflow activity, at design time.  I made the attached property for ErrorMessage written as an InArgument (to support some custom control that works well with InArguments).  Here's some of the design time code:

            AttachedProperty<InArgument<string>> ErrorMessage = new AttachedProperty<InArgument<string>>
            {
                OwnerType = typeof(ActivityBuilder),
                IsBrowsable = true,
                Name = "ErrorMessage",
                Getter = (mi =>
                {
                    InArgument<string> temp;
           &nbs

Attached property usage error (Repost for clarity)

  
<Window x:Class="WpfApplication4.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="WpfApplication4"
  Title="Window1" Height="300" Width="300">
  <Grid>
    <TextBox Height="23" Margin="86,0,72,106" Name="textBox1" VerticalAlignment="Bottom" Style="{StaticResource BigHonkingDigitOnlyTextBox}" />
  </Grid>

  <Window.Resources>
    <Style x:Key="BigHonkingDigitOnlyTextBox" TargetType="TextBox">
      <Setter Property="FontSize" Value="36" />
      <!-- honking

Attached property usage error

  
I am trying to use attached property...

And i get errors ... here is my code

<

Window x:Class 
="WpfApplication4.Window1"


 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 

xmlns:local="WpfApplication4" 
 

Title="Window1" Height="300" Width="300"> 
 

<Grid 
>


 

<TextBox Height="23" Margin="86,0,72,106" Name="textBox1" VerticalAlignment="Bottom" Style="{StaticResource BigHonkingDigitOnlyTextBox 
}" />


 

</Grid 
>


 

<Window.Resources 
>


 

<Style x:Key="BigHonkingDigitOnlyTextBox" TargetType 
="TextBox">


 

<Setter Property="FontSize" Value 
="36" />


 

<!-- big -->


 

<Setter Property="local:InputBehaviour.HonkOnKeyPress" Value 
="True" />


 

<!-- honking -->


 

<Setter Property="local:InputBehaviour.IsDigitOnly" Value 
="True" />


 

<!-- digit-only -->


 

</Style 
>


 

</Window.Resources 
>


 

 

</

Window>

 

 

 

 

using

 

System;

using

 

System.Collections.Generic;

using

 

System.Linq;

using

 

System.Text;

using

 

System.Windows;

using

 

System.Windo

WPF: If Heineken did MVVM Frameworks Part 4

  
MVVM is to have an instance of a particular Model (say currentPerson) inside my ViewModel (say PeopleViewModel) which is exposed to the View (say PeopleView). The View binds and edits the Model directly.

This definitely flies in the face of what most people consider to be the holy grail of MVVM pattern, but it's a fairly new pattern, so people are still finding their way with it every day, and this works for me very well. The reason I do what I do, is for the following reasons:

1.I have always had the luxury of being able to write my own UI specific Model classes. I would even do this if I was using some other Model classes first, such as LINQ to SQL or LINQ to Entity Framework. As these classes don't have everything a proper WPF Model class needs in my humble opinion. Though, they are pretty good, as they are Partial classes and use INotifyPropertyChanged/DataContract etc etc
2.I am a pragmatist and I do not like writing code for the sake of writing code. I have seen some MVVM apps where the author has had a Model with 50 properties on it, that are simply repeated in the ViewModel abstraction, where the ViewModel added nothing. On that day I decided I would never do that unless I have to.
3.I honestly see no harm in writing directly to the Model from the View, JUST SO LONG AS if the Model is InValid its data NEVER makes its way to the database. I honestly see no pro

WPF / Silverlight tutorial: Visibility property and binding

  
Visibility property is a very powerful and yet often overlooked property available in both WPF and Silverlight. It enables you to set Visibility of certain UIElement objects to different states like: Visible, Collapsed and Hidden (not supported by Silverlight). This tutorial shows you how to use it and how to bind to Visibility property

abstract away the source of the connection string using a class with a static property.

  
ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Encapsulation
Let's abstract away the source of the connection string using a class with a static property.

Get pixel format, raw format, property id list and property items image in VB.net - C#.net.

  
n this simple article you will learn that how we can get pixel format, raw format, property id list and property items image in VB and C#.net.

Get Pixel Format:

Image consists of pixels to get the format of the pixel we have a property named pixel format. This property returns an enumeration of pixel format. This enumeration tells the pixel format.

To demonstrate make a window application. Drag one button and a picture box on form.

Now write the following code on Button click event:
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend