Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataTemplate? Resource? not sure what?

$
0
0

i have the following usercontrol defined

<UserControl x:Class="ucReport"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="604" d:DesignWidth="808"><Grid><Grid.RowDefinitions><RowDefinition Height="30" /><RowDefinition Height="532*" /><RowDefinition Height="30" /></Grid.RowDefinitions><StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"><TextBlock Width="33" Height="23" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,6,5,0">From:</TextBlock><DatePicker Name="dtpStart" Width="125" Height="23" SelectedDate="{Binding StartDate,Mode=TwoWay}" Margin="0,0,5,0" /><TextBlock Width="33" Height="23" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,6,5,0">To:</TextBlock><DatePicker Name="dtpEnd" Width="125" Height="23" SelectedDate="{Binding EndDate,Mode=TwoWay}"/><Button Name="btnRefresh" Width="72" Height="23" Margin="1,0,40,0" Command="{Binding ReloadCommand}">_Refresh</Button></StackPanel><ContentPresenter Grid.Row="1" Content="{Binding Viewer}"/><StackPanel Grid.Row="2"  Orientation="Horizontal" HorizontalAlignment="Right"><Button Name="btnOK" Width="72" Height="23" Margin="1,0" Click="btnOK_Click" Command="{Binding CleanUpCommand}">_OK</Button><Button Name="btnCancel" Width="72" Height="23" Margin="1,0" Click="btnCancel_Click" Command="{Binding CleanUpCommand}">_Cancel</Button></StackPanel></Grid></UserControl>

I use dependency injection to display different ViewModels like so, in my code behind i inject an IReportViewModel

Public Class ucReport

    Private WithEvents m_genericVM As IReportViewModel
    Public Sub New(view As IReportViewModel)
        InitializeComponent()
        m_genericVM = view
        DataContext = m_genericVM
    End Sub
End Class

IReportViewModel has the following

    Public Interface IReportViewModel
        Property Viewer As WindowsFormsHost
    End Interface

so as you can see, contentpresenter in the xaml code binds to Viewer.

Now i would like to remove the stack panel containing buttons etc from that xaml too.

So my question is how would i do this.

I've thought about these two options.

1) I define a datatemplate and somehow load this into the concrete ViewModel during construction,  define a contentpresenter in the xaml, add another property to IReportViewModel.

2) construct visual tree manually in code in the Viewmodel, yuck. define a contentpresenter in the xaml, add another property to IReportViewModel.

With option one i am not sure how i would load the datatemplate.

Any Ideas.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>