how can I access a property from a XAML ControlTemplate? - wpf

I have the following Style for a DocumentViewer:
<Style x:Key="MyDocumentViewerStyle" TargetType="{x:Type DocumentViewer}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DocumentViewer}">
<Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Focusable="False">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="1" CornerRadius="2" HorizontalAlignment="Stretch" BorderThickness="0">
<ToolBar HorizontalAlignment="Center" Height="35"
ToolBarTray.IsLocked="True" KeyboardNavigation.TabNavigation="Continue" ToolBar.OverflowMode="Never">
<Button Command="ApplicationCommands.Print" Margin="10,0"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<!--Content="Print">-->
<Image Source="/ApniCureConsole;component/Images/Print.png" ToolTip="Print report" />
</Button>
<Separator />
<Button Command="NavigationCommands.IncreaseZoom" Margin="10,0"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<!--Content="Zoom In">-->
<Image Source="/ApniCureConsole;component/Images/MagnifyPlus.png" ToolTip="Zoom in" />
</Button>
<Button Command="NavigationCommands.DecreaseZoom" Margin="10,0"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<!--Content="Zoom Out" />-->
<Image Source="/ApniCureConsole;component/Images/MagnifyMinus.png" ToolTip="Zoom out" />
</Button>
<Separator />
<Button Margin="10,0,10,0"
Content="SAVE REPORT"
ToolTip="Save the report"
Style="{StaticResource CommandButton}"
Command="{Binding Path=SaveReportCommand}"
CommandParameter="{Binding ????}" <------WHAT DO I PUT HERE?
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
</ToolBar>
</Border>
<ScrollViewer Grid.Row="0" CanContentScroll="true" HorizontalScrollBarVisibility="Auto" x:Name="PART_ContentHost" IsTabStop="true">
<ScrollViewer.Background>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
<GradientStop Color="#559CB7A4" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</ScrollViewer.Background>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I've defined the following elements in my application that use this Style:
<TabControl Style="{StaticResource MyTabControlStyle}" TabStripPlacement="Top" >
<TabItem Style="{StaticResource MyTabItemStyle}" IsTabStop="False">
<TabItem.Header>
<TextBlock Text="REPORT ONE" Height="18" Padding="10, 0" FontSize="14" Style="{StaticResource MyTabItemText}"/>
</TabItem.Header>
<DocumentViewer Name="ReportOne" IsTabStop="False" Document="{Binding Report1}" ContextMenu="{x:Null}" Style="{StaticResource MyDocumentViewerStyle}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0" BorderBrush="#FF00668E">
</DocumentViewer>
</TabItem>
<TabItem Style="{StaticResource MyTabItemStyle}" IsTabStop="False">
<TabItem.Header>
<TextBlock Text="REPORT TWO" Height="18" Padding="10, 0" FontSize="14" Style="{StaticResource MyTabItemText}"/>
</TabItem.Header>
<DocumentViewer Name="ReportTwo" IsTabStop="False" Document="{Binding Report2}" ContextMenu="{x:Null}" Style="{StaticResource MyDocumentViewerStyle}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="0" BorderBrush="#FF00668E">
</DocumentViewer>
</TabItem>
</TabControl>
My question is, how can I find out what the value for the "Name" property is from the XAML, so I can pass it my ViewModel?

Assuming that you want to pass the Name of the DocumentViewer as the CommandParameter to the ViewModel, the easiest is to use
CommandParameter="{TemplateBinding Name}"
which will bind the name of the templated control to the CommandParameter.

Related

How to change button filter color in datagridview when filtering

Hello I want to change color of filter packicon while filtering data from data GridView.
My GridView design like this:-
I want change filter icon color when I pressed apply filter button and remove color when I pressed remove button.
XML code for GridViewColumnHeader:-
<DataGrid HorizontalAlignment="Left" Height="975" VerticalAlignment="Top" Width="1894" AlternationCount="2" AutoGenerateColumns="False"
ItemsSource="{Binding Products}" SelectedItem="{Binding IsSelected}" x:Name="dataGrid" Margin="10,75,-1144,0">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Height" Value="50" />
<Setter Property="SeparatorBrush" Value="DarkRed" />
<Setter Property="FontWeight" Value="Black" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid>
<Border x:Name="columnHeaderBorder"
BorderThickness="1"
Padding="3,0,3,0">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#ecebf2" />
<GradientStop Offset="1" Color="#ecebf2" />
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#575757" />
<GradientStop Offset="1" Color="#575757" />
</LinearGradientBrush>
</Border.Background>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal" Visibility="Visible" Background ="Transparent" >
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="White" Background="Transparent" HorizontalAlignment="Center" Margin="0,5" >
</TextBlock>
<Button x:Name="btnfilter" Command="{ Binding ApplyFilterCommand}" Click="Btnfilter_Click" HorizontalContentAlignment="Right"
HorizontalAlignment="Right" BorderBrush="Transparent" Background="Transparent" Margin="0,-2" >
<materialDesign:PackIcon x:Name="FilterIcon" Kind="Filter" Foreground="White" BorderThickness="0" BorderBrush="Transparent" HorizontalContentAlignment="Right" VerticalAlignment="Center">
<materialDesign:PackIcon.Style>
<Style TargetType="materialDesign:PackIcon" >
<Style.Triggers>
<DataTrigger Binding="{Binding Boolfilteractivate}">
<Setter Property="Foreground" Value="Black">
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon>
</Button>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
It is common template for all GridViewColumnHeader.
Please suggest how to change filtericon color for particular column.
POPUP code for column header:-
<Popup x:Name="popExcel" Width="300" Height="300" Placement="Bottom" StaysOpen="False">
<Border Background="White" BorderBrush="Gray" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox x:Name="tbfilter" BorderBrush="Gray" Text="" Foreground="Black" BorderThickness="3" Height="30" Grid.Row="0" Margin="10" TextChanged="Tbfilter_TextChanged" KeyDown="Tbfilter_KeyDown"></TextBox>
<Separator Grid.Row="0" VerticalAlignment="Bottom" Margin="10,0" Height="3"/>
<ListBox x:Name="lbfilter" BorderBrush="Black" BorderThickness="0" Grid.Row="1" Margin="10">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource MaterialDesignAccentCheckBox}" Background="Gray"
IsChecked="{Binding Is_Check, UpdateSourceTrigger=PropertyChanged}" Content="{Binding Title}"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="ApplyFilter" Style="{StaticResource MaterialDesignRaisedButton}" Foreground="White" Command="{Binding ApplyFilterCommand }" Background="#575757" Click="ApplyFilter_Click" Grid.Row="2" Margin="10">Apply Filter</Button>
<Button x:Name="ClearFilter" Style="{StaticResource MaterialDesignRaisedButton}" Foreground="White" Background="#575757" Click="ClearFilter_Click" Grid.Row="3" Margin="10">Remove Filter</Button>
</Grid>
</Border>
</Popup>
How can we call packicon as child of button
like:-
string colName = "";
Button btn = sender as Button;
ObservableCollection<FilterObj> fltcurrent;
popExcel.PlacementTarget = btn;
StackPanel sp = btn.Parent as StackPanel;
foreach(var ch in sp.Children)
{
if(ch is TextBlock tb)
{
colName = tb.Text;
break;
}
}
foreach (var ch in sp.Children)
{
if (ch is Button bb)
{
}
Because I am unable to call packicon by name:-
Applyfiltermethod
Please help
I find the alternative solution:-
Here is the code:-
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal" Visibility="Visible" Background ="Transparent" >
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="White" Background="Transparent" HorizontalAlignment="Center" Margin="0,5" >
</TextBlock>
<Button x:Name="btnfilter" Click="Btnfilter_Click" HorizontalContentAlignment="Right"
HorizontalAlignment="Right" BorderBrush="Transparent" Background="Transparent" Margin="0,-2" >
<materialDesign:PackIcon x:Name="FilterIcon" Kind="Filter" Foreground="White" BorderThickness="0" BorderBrush="Transparent" HorizontalContentAlignment="Right" VerticalAlignment="Center">
</materialDesign:PackIcon>
</Button>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Some code need to add in CS file as well.
PackIcon wantedchild;
IList<PackIcon> wantedchilds = new List<PackIcon>();
Button button = sender as Button;
object wantedNode = button.FindName("FilterIcon");
if (wantedNode is PackIcon)
{
wantedchild = wantedNode as PackIcon;
wantedchilds.Add(wantedchild);
}
Add button code:-`
foreach(var child in wantedchilds)
{
child.Foreground = Brushes.Blue;
} `
Remove button code:-
foreach (var child in wantedchilds)
{
child.Foreground = Brushes.White;
}
wantedchilds.Clear();

Button sizes changing on user control when control is added to window

Okay, so I created a user control for a keypad. It looks like this:
The code for this is:
<DockPanel DockPanel.Dock="Left">
<StackPanel DockPanel.Dock="Left">
<Button Content="1"
Height="60"
Width="60"
Margin="8"
Name="bttnOne" />
<Button Content="4"
Height="60"
Width="60"
Margin="8"
Name="bttnFour" />
<Button Content="7"
Height="60"
Width="60"
Margin="8"
Name="bttnSeven" />
<Button Content="0"
Height="60"
Width="60"
Margin="8"
Name="bttnZero" />
</StackPanel>
<StackPanel DockPanel.Dock="Left">
<Button Content="2"
Height="60"
Width="60"
Margin="8"
Name="bttnTwo" />
<Button Content="5"
Height="60"
Width="60"
Margin="8"
Name="bttnFive" />
<Button Content="8"
Height="60"
Width="60"
Margin="8"
Name="bttnEight" />
<Button Content="."
Height="60"
Width="60"
Margin="8"
Name="bttnDecimal" />
</StackPanel>
<DockPanel DockPanel.Dock="Left">
<StackPanel DockPanel.Dock="Bottom">
<Button Content="Del"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Width="Auto"
Margin="8"
Height="60"
Name="bttnDelete" />
</StackPanel>
<StackPanel DockPanel.Dock="Left">
<Button Content="3"
Height="60"
Width="60"
Margin="8"
Name="bttnThree" />
<Button Content="6"
Height="60"
Width="60"
Margin="8"
Name="bttnSix" />
<Button Content="9"
Height="60"
Width="60"
Margin="8"
Name="bttnNine" />
</StackPanel>
<StackPanel DockPanel.Dock="Left"
Orientation="Horizontal">
<Button Content="Ent"
HorizontalAlignment="Stretch"
VerticalContentAlignment="Center"
Width="60"
Margin="8"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Center"
Height="Auto"
Name="bttnEnter" />
</StackPanel>
</DockPanel>
</DockPanel>
Now, when I added the keypad to the window, the window changes the size of the buttons, like this:
The code for that is:
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<Label Content="New Item"
Style="{StaticResource MyLabel2}"
FontStyle="Italic" />
</StackPanel>
<StackPanel DockPanel.Dock="Left"
Margin="0,20,0,0">
<Label Content="BHA Description"
HorizontalContentAlignment="Right"
FontSize="20" />
<Label Content="" />
<Label Content="OD"
HorizontalContentAlignment="Right"
FontSize="20" />
<Label Content="" />
<Label Content="Length"
HorizontalContentAlignment="Right"
FontSize="20" />
<Label Content="" />
<Button Name="bttnSave"
Content="Save"
Margin="2,14,2,2" />
</StackPanel>
<StackPanel DockPanel.Dock="Left"
Margin="10,20,25,0">
<ComboBox Name="cmbDesc"
HorizontalContentAlignment="Right"
FontSize="23" />
<Label Content="" />
<ComboBox Name="cmbOd"
HorizontalContentAlignment="Right"
FontSize="23" />
<Label Content="" />
<TextBox Text="Length"
HorizontalContentAlignment="Right"
FontSize="25"
MaxLength="10" />
<Label Content="" />
<Button Name="bttnCancel"
Content="Cancel"
Click="bttnCancel_Click"
Margin="2,14,2,2" />
</StackPanel>
<StackPanel DockPanel.Dock="Left">
<UserControls:Keypad />
</StackPanel>
</DockPanel>
Now, I do have a default button style, who's code is:
<Style TargetType="{x:Type Button}"
BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Margin"
Value="2" />
<Setter Property="FontFamily"
Value="Calibri" />
<Setter Property="FontSize"
Value="16px" />
<Setter Property="FontWeight"
Value="Bold" />
<Setter Property="Height"
Value="75" />
<Setter Property="Width"
Value="150" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1"
MappingMode="RelativeToBoundingBox"
StartPoint="0.5,0">
<GradientStop Color="#FFF5EFEF"
Offset="0" />
<GradientStop Color="#FFA09C9C"
Offset="0.808" />
<GradientStop Color="#FFA09C9C"
Offset="1" />
<GradientStop Color="#FFF5EFEF"
Offset="0.192" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="2"
Padding="4,2"
BorderBrush="Black"
CornerRadius="7"
Background="{TemplateBinding Background}">
<Grid>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
Name="contentShadow"
Style="{StaticResource ShadowStyle}">
<ContentPresenter.RenderTransform>
<TranslateTransform X="1.0"
Y="1.0" />
</ContentPresenter.RenderTransform>
</ContentPresenter>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
Name="content" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="border"
Property="BorderBrush"
Value="Red" />
<Setter Property="Foreground"
Value="Red" />
</Trigger>
<Trigger Property="IsPressed"
Value="True">
<Setter Property="Foreground"
Value="#FFFDFDFD" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1"
MappingMode="RelativeToBoundingBox"
StartPoint="0.5,0">
<GradientStop Color="Red"
Offset="0" />
<GradientStop Color="Red"
Offset="1" />
<GradientStop Color="Black"
Offset="0.573" />
<GradientStop Color="Black"
Offset="0.402" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="content"
Property="RenderTransform">
<Setter.Value>
<TranslateTransform Y="1.0" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
My question is, why are the buttons reverting to the default setting, when I'm hardcoding height/width values in the user control itself? How can I fix it so that it doesn't do that?
I'd use a Grid based layout:
I'd imagine DockPanel and the StackPanel instances are doing some weird stuff - and to be honest if you want a uniform grid such as a keypad, it's the way to go
<Grid>
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="8" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0">1</Button>
<Button Grid.Column="1" Grid.Row="0">2</Button>
<Button Grid.Column="2" Grid.Row="0">3</Button>
<Button Grid.Column="3" Grid.Row="0" Grid.RowSpan="3">Ent</Button>
<Button Grid.Column="0" Grid.Row="1">4</Button>
<Button Grid.Column="1" Grid.Row="1">5</Button>
<Button Grid.Column="2" Grid.Row="1">6</Button>
<Button Grid.Column="0" Grid.Row="2">7</Button>
<Button Grid.Column="1" Grid.Row="2">8</Button>
<Button Grid.Column="2" Grid.Row="2">9</Button>
<Button Grid.Column="0" Grid.Row="3">0</Button>
<Button Grid.Column="1" Grid.Row="3">.</Button>
<Button Grid.Column="2" Grid.Row="3" Grid.ColumnSpan="2">Del</Button>
</Grid>
It will also scale perfectly no matter how big or small you want to make it - if needs be you can do some template bindings to set properties such as the button margins etc. via the usercontrol properties
I don't really ever use DockPanel if I can help it - I don't think it's the most intuitive of controls
Edit: I added your calc layout and the one above side by side in a 400 x 400 area - this is the result
(ignore the 1 button on the grid layout, I explicitly set the width to 150 while I was testing styles and forgot to set it back! If you remove the explicit width it scales perfectly like the other buttons)
You have don't have your LastChildFill property set to False on your top DockPanel. This is the reason "Ent" is changing size and moving your screen.
You also have the HorizontalAlignment on "Del" set to stretch. Try setting that to Left, but might be moot with the LastChildFill correction.
The overall resizing is do to HorizontalAlignment set to Stretch set that to Left.

WP7 - VirtualizingStackPanel bottom margin does not work

I have VirtualizingStackPanel in ListBox ItemsPanel. If I set Margin="0,0,0,50" then margin is not showed but if I set left margin (or top or right) Margin="50,0,0,0" then margin works correct.
If I change VirtualizingStackPanel for StackPanel then bottom margin works well.
This Is my code:
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<ListBox x:Name="TasksListBox"
Margin="0"
ItemsSource="{Binding Tasks}"
HorizontalAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<!--<StackPanel Margin="0,0,0,14" />-->
<VirtualizingStackPanel Margin="0,0,0,100"
Height="Auto" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Background="White"
Width="455"
Height="105"
Tag="{Binding Id}"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Click="Button_Click_1">
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="24" />
</Grid.RowDefinitions>
<TextBlock Grid.ColumnSpan="4"
Text="{Binding Name}"
FontSize="24"
Foreground="#400000" />
<Image Grid.Row="1"
Visibility="{Binding Project, Converter={StaticResource StringToVisibilityConverter}}"
Source="/Images/ProjectIcon.png"
Width="20"
Height="18"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,0,5,0" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Visibility="{Binding Project, Converter={StaticResource StringToVisibilityConverter}}"
Text="{Binding Project, Converter={StaticResource ToUppercaseConverter}}"
FontSize="16"
Foreground="#666666"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,-2,9,0"
LineStackingStrategy="BlockLineHeight" />
<Image Grid.Row="1"
Grid.Column="2"
Visibility="{Binding Context, Converter={StaticResource StringToVisibilityConverter}}"
Source="/Images/ContextIcon.png"
Width="20"
Height="18"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="-3,1,1,0" />
<TextBlock Grid.Row="1"
Grid.Column="3"
Visibility="{Binding Context, Converter={StaticResource StringToVisibilityConverter}}"
Text="{Binding Context, Converter={StaticResource ToUppercaseConverter}}"
FontSize="16"
Foreground="#666666"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,-2,0,0"
LineStackingStrategy="BlockLineHeight" />
</Grid>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick_1" />
</toolkit:GestureService.GestureListener>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu IsZoomEnabled="False"
BorderBrush="#9c0605"
Foreground="#400000">
<toolkit:MenuItem Header="dokonĨeno"
Foreground="#400000"
Tag="{Binding Id}"
Click="MenuItem_Click_1" />
<toolkit:MenuItem Header="upravit"
Foreground="#400000"
Tag="{Binding Id}"
Click="MenuItem_Click_2" />
<toolkit:MenuItem Header="odstranit"
Foreground="#400000"
Tag="{Binding Id}"
Click="MenuItem_Click_3" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Code Behind
ObservableCollection<string> data = new ObservableCollection<string>();
for (int i = 0; i < 40; i++)
{
data.Add("Item" + i);
}
lbTest.ItemsSource = data;
Xaml
<Grid x:Name="LayoutRoot"
Background="Transparent">
<ListBox x:Name="lbTest">
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Foreground"
Value="{StaticResource PhoneForegroundBrush}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility"
Value="Auto" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="BorderBrush"
Value="Transparent" />
<Setter Property="Padding"
Value="0,0,0,150" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
Padding="{TemplateBinding Padding}">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
</ListBox>
</Grid>

How to make usercontrol take whole space of the region its injected into

I have a view which is injected into an region (Itemscontrol). The view only takes up space in the region depending on content size. I want that the view streches for whole height of the region. Here is code of my view:
<UserControl x:Name="userControl" x:Class="DishPromo.Modules.Payments.SideCart.SideCartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:infUIFramework="clr-namespace:DishPromo.Infrastructure.UIFramework;assembly=DishPromo.Infrastructure"
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:Convert="clr-namespace:DishPromo.Modules.Payments.SideCart"
mc:Ignorable="d" >
<UserControl.Resources>
<Convert:ObjectToStringConverter x:Key="ToString" />
<Convert:BooleanToVisibilityConverter x:Key="ToVisibility" />
<Convert:WOMsgVisibilityConverter x:Key="WOMsgVisibility" />
<Convert:WorkOrderMsgConverter x:Key="WorkOrderMsg" />
<Convert:RescheduleValueConverter x:Key="ValueConverter" />
<Convert:PaymentAmountDueNow x:Key="PaymentAmountDueNow" />
<Style TargetType="Button" x:Key="hotkeyStyle">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="25"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<Border Name="border"
Padding="4,2" CornerRadius="3"
BorderBrush="DarkGray"
/>
<Rectangle x:Name="FVElement" Stretch="Fill" StrokeLineJoin="Miter" StrokeThickness="0.5" Opacity="0" RadiusX="2" RadiusY="2"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="{StaticResource {x:Static SystemColors.ControlLightLightBrushKey}}" Stroke="{StaticResource OEFlowButtonBorderStyle}"
>
</Rectangle>
<Rectangle x:Name="Background" StrokeLineJoin="Miter" StrokeThickness="0.5" Opacity="1" Margin="2" RadiusX="3" RadiusY="3">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="{StaticResource {x:Static SystemColors.ControlColorKey}}" Offset="0.576" />
<GradientStop Color="{StaticResource {x:Static SystemColors.ControlLightLightColorKey}}" Offset="0" />
<GradientStop Color="{StaticResource {x:Static SystemColors.ControlColorKey}}" Offset="1" />
<GradientStop Color="{StaticResource {x:Static SystemColors.ControlLightColorKey}}" Offset="0.262" />
</LinearGradientBrush>
</Rectangle.Fill>
<Rectangle.Stroke>
<LinearGradientBrush EndPoint="0.5,-1.85" StartPoint="0.5,1.5">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Stroke>
</Rectangle>
<Path x:Name="WhiteBand" Height="4.25" Stretch="Fill" StrokeLineJoin="Miter" Fill="{StaticResource OEFlowButtonWhiteBandFillStyle}"
Data="M4.2160064,2.75 C4.2160064,1.6454305 5.1114369,1.7153466 6.2160064,1.7153466 L22.679308,1.7153466 C23.783877,1.7153466 24.679308,1.6454305 24.679308,2.75 24.679308,2.75 4.2160064,2.75 4.2160064,2.75 z"
Margin="7,4,7,0" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" FontWeight="Light"
TextWrapping="WrapWithOverflow" Text="{TemplateBinding Content}" x:Name="btnName" >
</TextBlock>
<ContentPresenter />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF585151" />
<Setter Property="Cursor" Value="Hand" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#FF219921" Offset="0.35"/>
<GradientStop Color="#FF216B99" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="RenderTransform" >
<Setter.Value>
<TranslateTransform Y="0.5" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.3" />
<Setter TargetName="Background" Property="Opacity" Value="0.3" />
<Setter TargetName="FVElement" Property="Opacity" Value="0.3" />
<Setter TargetName="btnName" Property="Foreground" Value="Gray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<DockPanel VerticalAlignment="Stretch" LastChildFill="True" >
<DockPanel.InputBindings>
<KeyBinding Command="{Binding MinPaymentOverride}" Gesture="SHIFT+CTRL+y"></KeyBinding>
<KeyBinding Command="{Binding PIAMinPaymentOverride}" Gesture="SHIFT+CTRL+m"></KeyBinding>
<KeyBinding Command="{Binding EFTOverride}" Gesture="SHIFT+CTRL+e"></KeyBinding>
<KeyBinding Command="{Binding CCOverride}" Gesture="SHIFT+CTRL+c"></KeyBinding>
<KeyBinding Command="{Binding OverrideCC}" Gesture="SHIFT+CTRL+c"></KeyBinding>
<KeyBinding Command="{Binding OverrideSSN}" Gesture="SHIFT+CTRL+s"></KeyBinding>
<KeyBinding Command="{Binding OverrideCertificate}" Gesture="SHIFT+CTRL+j"></KeyBinding>
<KeyBinding Command="{Binding OverrideSellingAgent}" Gesture="SHIFT+CTRL+d"></KeyBinding>
<KeyBinding Command="{Binding OverrideRefCompany}" Gesture="SHIFT+CTRL+i"></KeyBinding>
<KeyBinding Command="{Binding OverrideSellingCompany}" Gesture="SHIFT+CTRL+n"></KeyBinding>
</DockPanel.InputBindings>
<DockPanel.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ChangeFocus}" Value="True">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=SidecartRemove}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
<!--<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>-->
<DockPanel x:Name="dpNotificationArea" Margin="0" VerticalAlignment="Bottom" AllowDrop="True" LastChildFill="True" >
<!--<Grid.RowDefinitions>
<RowDefinition MinHeight="350" />
<RowDefinition Height="29"/>
<RowDefinition Height="58"/>
<RowDefinition Height="27"/>
</Grid.RowDefinitions>-->
<Grid Grid.Row="3" VerticalAlignment="Bottom" DockPanel.Dock="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="260"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Width="Auto" FontWeight="Bold" Foreground="Red">
<MultiBinding Converter="{StaticResource PaymentAmountDueNow}">
<Binding Path="CustomerModel.AccountInfo.Pricer.PaymentRequired"/>
<Binding Path="CustomerModel.AccountInfo.AccountStatus"/>
</MultiBinding>
</Label>
<StackPanel Grid.Column="1" x:Name="spPricerActionBar" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
<Button Style="{StaticResource hotkeyStyle}" Width="80" x:Name="SidecartRemove" Command="{Binding RemoveCartItem}"
IsEnabled="{Binding CustomerModel.ControlStatus.RemoveIsEnabled}" GotFocus="SidecartRemove_GotFocus">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black" FontWeight="Light"><Run Text="Re"/><Underline><Run Text="m"/></Underline><Run Text="ove"/></TextBlock>
</Button>
<Button x:Name="btnFeeWaived" Width="80" Content="Fees Waived" IsEnabled="{Binding IsFeeWaivedEnabled}"
Command="{Binding ShowBattery}" GotFocus="btnFeeWaived_GotFocus" />
<Button Width="100" Content="Price It" HorizontalAlignment="Right" Visibility="{Binding PriceItVisibility}" Command="{Binding GetPricing}" Background="#FF6633" Style="{StaticResource PriceItStyle}"/>
</StackPanel>
</Grid>
<StackPanel x:Name="spWorkOrder" Grid.Row="2" VerticalAlignment="Bottom" DockPanel.Dock="Bottom">
<Grid Margin="0,0,0,6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="75" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" VerticalAlignment="Bottom">
<Button Width="70" Height="25" x:Name="btnReschedule1" Content="Reschedule" HorizontalAlignment="Right" Command="{Binding GetInstallDates}" CommandParameter="1"
Visibility="{Binding CustomerModel.AccountInfo.ScheduleInfo, ConverterParameter=1, Converter={StaticResource ToVisibility}}" />
<Button Width="70" x:Name="btnReschedule0" Content="Reschedule" HorizontalAlignment="Right" Command="{Binding GetInstallDates}" CommandParameter="0"
Visibility="{Binding CustomerModel.AccountInfo.ScheduleInfo, ConverterParameter=0, Converter={StaticResource ToVisibility}}" />
</StackPanel>
<StackPanel Grid.Column="0" VerticalAlignment="Bottom">
<Label Margin="0,5,0,5" Content="{Binding CustomerModel.AccountInfo.WorkorderInfo.DisconnectDate, Converter={StaticResource WorkOrderMsg}}"
HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Visibility="{Binding CustomerModel.AccountInfo.WorkorderInfo.DisconnectDate, ConverterParameter=0, Converter={StaticResource WOMsgVisibility}}" VerticalAlignment="Center"/>
<Label Margin="0,5,0,5" Content="{Binding CustomerModel.AccountInfo.ScheduleInfo[1], Converter={StaticResource ValueConverter}}"
HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Visibility="{Binding Visibility, ElementName=btnReschedule1}" VerticalAlignment="Center"/>
<Label Margin="0,5,0,5" Content="{Binding CustomerModel.AccountInfo.ScheduleInfo[0], Converter={StaticResource ValueConverter}}"
HorizontalAlignment="Left" FontWeight="Bold" Foreground="Blue" Visibility="{Binding Visibility, ElementName=btnReschedule0}" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
</StackPanel>
<StackPanel x:Name="NetworkQualification" Grid.Row="1" Margin="4,0,0,0" VerticalAlignment="Bottom" DockPanel.Dock="Bottom">
<TextBlock x:Name="txtbNetQualStatus" Text="{Binding CustomerModel.ServiceAddress.NetQualResult}" Foreground="Blue" FontWeight="Bold" />
<TextBlock x:Name="txtDupAddress" Text="{Binding CustomerModel.ServiceAddress.NoAddressFound}" Foreground="Blue" FontWeight="Bold"/>
</StackPanel>
<ListView Grid.Row="0" Name="lstSideCart" ScrollViewer.HorizontalScrollBarVisibility="Auto" DockPanel.Dock="Top"
ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding CustomerModel.AccountInfo.Services}" SelectionMode="Extended"
SelectionChanged="lstSideCart_SelectionChanged" MaxHeight="781" VerticalContentAlignment="Stretch" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Foreground" Value="{Binding Path=ForegroundColor}"/>
<Setter Property="FontWeight" Value="{Binding Path=FontWeight}"/>
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="DarkGray" Offset="0.0" />
<GradientStop Color="DarkGray" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0,0,0,0.5"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ContextMenu>
<ContextMenu ItemsSource="{Binding ContextMenuList}">
<ContextMenu.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Path=Header}" CommandParameter="{Binding}"
Click="MenuItem_Click" Visibility="{Binding Path=IsVisible}" Height="16"/>
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</ListView.ContextMenu>
<ListView.View>
<GridView>
<GridViewColumn Width="175" Header="Service Code Name" DisplayMemberBinding="{Binding Description}" />
<GridViewColumn Width="100" Header="Service Type" DisplayMemberBinding="{Binding ServiceCode.SecondaryServiceTypeSingle.ServiceTypeName}"/>
<GridViewColumn Width="25" Header="#" DisplayMemberBinding="{Binding CurrentQuantity}"/>
<GridViewColumn Width="68" Header="Added" DisplayMemberBinding="{Binding Path=DateAdded, StringFormat={}{0:MM/dd/yy}}"/>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
</DockPanel>
What's the ItemsPanelTemplate of your ItemsControl?
The default is a StackPanel, which won't automatically stretch its child elements to the maximum allowed size.
You'll either have to set HorizontalAlignment to Stretch in the ItemsContainerStyle, or change the ItemsPanelTemplate to something that automatically stretches its children.
<!-- ItemContainerStyle -->
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</ItemsControl.ItemContainerStyle>
How about using a UniformGrid for your ItemsPanelTemplate like so
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Also, StackPanels by their definition only take up space according to the content which exists, so saying something like VerticalAlignment="Stretch" won't stretch the contents of the StackPanel throughout the parent container.
Try to use a Grid as the layoutroot of your usercontrol and dont set the width and height.

Can I bind to use content from the controls nested in the templated parent?

I want to use the System.Windows.Controls.DocumentViewer to view a FixedDocument I created from a PDF file using TallComponents.PDF.Rasterizer. This is working, however, I want to disable or remove some of the toolbar buttons displayed by the DocumentViewer control. I'm using the template exmaple from here.
<Style x:Key="{x:Type DocumentViewer}"
TargetType="{x:Type DocumentViewer}">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="FocusVisualStyle"
Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DocumentViewer}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Focusable="False">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ToolBar ToolBarTray.IsLocked="True"
KeyboardNavigation.TabNavigation="Continue">
<Button Command="NavigationCommands.IncreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom In" />
<Button Command="NavigationCommands.DecreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom Out" />
<Separator />
<!--
<Button Command="NavigationCommands.Zoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="100.0"
Content="Actual Size" />
-->
<Button Command="DocumentViewer.FitToWidthCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Fit to Width" />
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="1"
Content="Whole Page" />
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="2"
Content="Two Pages" />
</ToolBar>
<ScrollViewer Grid.Row="1"
CanContentScroll="true"
HorizontalScrollBarVisibility="Auto"
x:Name="PART_ContentHost"
IsTabStop="true">
<ScrollViewer.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="{DynamicResource ControlLightColor}"
Offset="0" />
<GradientStop Color="{DynamicResource ControlMediumColor}"
Offset="1" />
</LinearGradientBrush>
</ScrollViewer.Background>
</ScrollViewer>
<ContentControl Grid.Row="2"
x:Name="PART_FindToolBarHost"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This is very similar to the linked example but I have removed the Print and Copy command buttons. I don't want the users to be able to use those buttons.
I also had to comment out the Zoom command, the IDE complained this was not a valid command, bonus votes for the answer to that problem.
This all works but after templating I no longer get the images on the tool bar buttons, just the text I specified in Content. So my question is, "Can I bind to use content from the controls nested in the templated parent?"
Here's what I got when I used Blend to extract and edit the template for the DocumentViewer. I commented out the two buttons you mentions.
As far as the Zoom commands, it might have complained about invalid commands because you were missing a namespace import for System.Windows.Documents.
Xaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System_Windows_Documents="clr-namespace:System.Windows.Documents;assembly=PresentationUI"
x:Class="WpfApplication6.Page2"
x:Name="Page"
WindowTitle="Page"
FlowDirection="LeftToRight"
Width="640" Height="480"
WindowWidth="640" WindowHeight="480">
<Page.Resources>
<Style x:Key="DocumentViewerStyle1" BasedOn="{x:Null}" TargetType="{x:Type DocumentViewer}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ContextMenu" Value="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerContextMenu, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DocumentViewer}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Focusable="False">
<Grid Background="{TemplateBinding Background}" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentControl Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="0" Style="{DynamicResource ContentControlStyle1}" TabIndex="0"/>
<ScrollViewer x:Name="PART_ContentHost" CanContentScroll="true" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalScrollBarVisibility="Auto" IsTabStop="true" Grid.Row="1" TabIndex="1"/>
<DockPanel Grid.Row="1">
<FrameworkElement DockPanel.Dock="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<Rectangle Height="10" Visibility="Visible" VerticalAlignment="top">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#66000000" Offset="0"/>
<GradientStop Color="Transparent" Offset="1"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</DockPanel>
<ContentControl x:Name="PART_FindToolBarHost" Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="2" TabIndex="2"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ContentControlStyle1" TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<ToolBar Focusable="{TemplateBinding Focusable}" ToolBarTray.IsLocked="True" Language="en-us" KeyboardNavigation.TabNavigation="Continue" Uid="ToolBar_2">
<!-- <Button x:Name="PrintButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerPrintButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" Command="ApplicationCommands.Print" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="0" ToolTip="Print (Ctrl+P)" Uid="Button_14" VerticalAlignment="Center" Width="24"/> -->
<!-- <Button x:Name="CopyButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerCopyButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" Command="ApplicationCommands.Copy" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="1" ToolTip="Copy (Ctrl+C)" Uid="Button_15" VerticalAlignment="Center" Width="24"/> -->
<!-- <Separator Uid="Separator_110"/> -->
<Button x:Name="ZoomInButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerZoomInButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" Command="NavigationCommands.IncreaseZoom" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="3" ToolTip="Increase the size of the content (Ctrl +)" Uid="Button_16" VerticalAlignment="Center" Width="24"/>
<Button x:Name="ZoomOutButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerZoomOutButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" Command="NavigationCommands.DecreaseZoom" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="4" ToolTip="Decrease the size of the content (Ctrl -)" Uid="Button_17" VerticalAlignment="Center" Width="24"/>
<Separator Uid="Separator_111"/>
<Button x:Name="ActualSizeButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerActualSizeButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" CommandParameter="100.0" Command="NavigationCommands.Zoom" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="5" ToolTip="100% (Ctrl+1)" Uid="Button_18" VerticalAlignment="Center" Width="24"/>
<Button x:Name="PageWidthButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerPageWidthButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" Command="DocumentViewer.FitToWidthCommand" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="6" ToolTip="Page Width (Ctrl+2)" Uid="Button_19" VerticalAlignment="Center" Width="24"/>
<Button x:Name="WholePageButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerWholePageButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" CommandParameter="1" Command="DocumentViewer.FitToMaxPagesAcrossCommand" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="7" ToolTip="Whole Page (Ctrl+3)" Uid="Button_20" VerticalAlignment="Center" Width="24"/>
<Button x:Name="TwoPagesButton" Background="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerTwoPagesButton, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" CommandTarget="{Binding TemplatedParent, RelativeSource={RelativeSource TemplatedParent}}" CommandParameter="2" Command="DocumentViewer.FitToMaxPagesAcrossCommand" IsTabStop="True" Margin="2" Padding="2" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerButtonStyle, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}" ToolTipService.ShowOnDisabled="True" TabIndex="8" ToolTip="Two Pages (Ctrl+4)" Uid="Button_21" VerticalAlignment="Center" Width="24"/>
</ToolBar>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<DocumentViewer Style="{DynamicResource DocumentViewerStyle1}"/>
</Grid>

Resources