Created
January 28, 2015 02:22
-
-
Save Feddas/6ce6739ce3b23a1c8535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="ProjectName.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:viewmodel="clr-namespace:ProjectName.ViewModels" | |
Title="MainWindow" Height="350" Width="525"> | |
<Window.Resources> | |
<!-- This creates an instance of the TestViewModel held in the ProjectName.ViewModels namespace --> | |
<viewmodel:TestViewModel x:Key="TestViewModel" /> | |
</Window.Resources> | |
<Grid x:Name="LayoutRoot" DataContext="{StaticResource TestViewModel}"> | |
<TextBlock Text="{Binding TestProp}" x:Name="txtBlock" /> | |
</Grid> | |
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ProjectName.ViewModels; | |
namespace ProjectName | |
{ | |
public partial class MainWindow : Window | |
{ | |
/// <summary> | |
/// This property is if the ViewModel needs to be accessed in this codebehind | |
/// </summary> | |
private TestViewModel ViewModel | |
{ | |
get | |
{ | |
return (this.LayoutRoot.DataContext as TestViewModel); | |
} | |
} | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment