So, I have a UserControl
named ApplicationForm. It has some TextBoxes
and a Button
. Each TextBox has a Binding
. An example of it:
<xctk:WatermarkTextBox Watermark="PACAPIME" Text="{Binding NumPac}" Grid.Column="2" Grid.Row="2" />
Then, my View is bound to a ViewModel like this:
<UserControl x:Class="Verkooporder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:vm="clr-namespace:Koala" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1100">
<UserControl.Resources>
<vm:VerkooporderViewModel x:Key="VerkooporderViewModelDataSource"
d:IsDataSource="True"/>
</UserControl.Resources>
<UserControl.DataContext>
<Binding Source="{StaticResource VerkooporderViewModelDataSource}"/>
</UserControl.DataContext>
The corresponding property in my ViewModel is like this:
Private _oNumPac As String = ""
Public Property NumPac As String
Get
Return _oNumPac
End Get
Set(ByVal value As String)
_oNumPac = value
RaisePropertyChanged()
End Set
End Property
This is working great inside my UserControl. Now, I call my UserControl in my MainWindow:
<local:Verkooporder />
I want to be able to access the Property NumPac
like <local:Verkooporder NumPac="" />
but this isn't working.
Also, how can I have access to the Button Command
?
Public Shared _oNumPac As DependencyProperty = DependencyProperty.Register("NumPac",
GetType(String), GetType(VerkooporderViewModel), New PropertyMetadata(""))
Public Property NumPac As String
Get
Return GetValue(_oNumPac)
End Get
Set(value As String)
SetValue(_oNumPac, value)
End Set
End Property
But it doesn't show up when I try to type this:
<local:Verkooporder NumPac="Test" />
Notice that the properties are in the ViewModel of the UserControl
, not the code behind View