views:

147

answers:

2
Public Sub New(ByVal log As Entities.LogSystem)
    InitializeComponent()   
    Me.DataContext = log
End Sub

This is the the initializer for my custom control It passes in a single entity that has several property fields. This control is added to a parent control so that it appears in a stackpanel.

Anyway I am trying to get the specific data from this control into several different text boxes:

<UserControl x:Class="LogSystemPickerItem"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WavelengthIS.WISRED.UserControls"
    Width="579" Height="122">
    <UserControl.Resources>
        <local:LogSystemPickerItem x:Key="Log"/>
    </UserControl.Resources>

    <Grid DataContext="{Binding Source={StaticResource Log}}">
        <Label Height="30" Name="Label1" VerticalAlignment="Top" Content="{Binding deptDescription}"/>

    </Grid>
</UserControl>

As you can see i havent really gotten too far. I have tried many different ways to do this including using dependency properties...I just really cant find a tutorial that shows this specific circumstance...can anyone point me in the right direction?

A: 

If you're setting the DataContext in the code behind as per your first code snippet, there's no need to also do it in the XAML, so you can remove the "Log" resource and the corresponding DataContext assignment on the Grid.

Once you've done that, it should work assuming there is a deptDescription property on your log class.

HTH, Kent

Kent Boogaart
sweet that worked. BUT...I really would rather have it in the XAML so that I can have designtime access to the control. I had it working with a datagrid, but I couldnt figure out how to do it in the textbox. Also I had a casing issue with the deptDescription should have been DeptDescription. So I have the xaml correct too? its just a matter of either/or?
ecathell
A: 

... and in XAML you may do it this way...

<UserControl.DataContext>
    <local:LogSystemPickerItem/>
</UserControl.DataContext>
Trainee4Life
doing it this way causes my IDE to crash.
ecathell