0

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

Sheridan
  • 68,826
  • 24
  • 143
  • 183
Krowi
  • 1,565
  • 3
  • 20
  • 40
  • 1
    You have to odeclare the `NumPac` property as a dependency property and implement it to call its `DependecyObject`'s `GetValue` and `SetValue` methods. – grizzly Mar 12 '14 at 19:39
  • `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` bit it doesn't show up when I try to type this: `` Doesn't show `NumPac` in intellisence – Krowi Mar 12 '14 at 19:57
  • 1
    Notice that the properties are in the ViewModel of the Usercontrol, not the code behind View – Krowi Mar 12 '14 at 20:09
  • I tried something out like this : http://stackoverflow.com/a/15133840/3357699. DependencyProperty in the code behind of the View and then a property in the ViewModel. But it just doesn't update the DependencyProperty if I change the property in the view model. – Krowi Mar 12 '14 at 23:19

0 Answers0