It is my first time working with a GridSplitter in WPF. I am trying to allow the user to resize the grid that contains 2 main controls. On top is a datagrid, below is a button with a map image over it. This is what it looks like in the designer. I have a separate row just for the gridsplitter. The xaml for the row definitions is
<Grid.RowDefinitions>
<RowDefinition Height="37" />
<RowDefinition Height="274*" />
<RowDefinition Height="13*"/>
<RowDefinition Height="272*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
Interestingly, the GridSplitter seems to work if I'm moving it down. Then I can move it as needed and functions correctly. However, it seems that if I move the splitter above where the line for the row defined above it is, I am unable to move it down again. I can only continue to move it further up.
I have attached a link to a gif showing the behavior that I talk about here.
I am wondering how to go about making the GridSplitter function the same when moving it up or down, as right now, the functionality is correct only if it is moved down from it's initial starting position.
Any help is appreciated.
Update: Here is the full xaml for the user control holding the grid:
<UserControl x:Class="LWDCM.Views.JobsControl"
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:local="clr-namespace:LWDCM.Views"
xmlns:Properties="clr-namespace:LWDCM.Properties"
xmlns:Utility="clr-namespace:LWDCM.Utility"
xmlns:Styles="clr-namespace:LWDCM.Styles"
xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Converters="clr-namespace:LWDCM.Converters"
mc:Ignorable="d"
Name="jobsControl"
MinWidth="800"
MinHeight="600"
>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/AppStyles.xaml" />
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="MainGrid"
Margin="0,0,0,0"
Background="#26598c"
>
<!--<Grid.Background>
<LinearGradientBrush ColorInterpolationMode="SRgbLinearInterpolation"
StartPoint="0.5, 0.0"
EndPoint="0.5, 1.0">
<GradientStopCollection>
<GradientStop Color="#FF111111"
Offset="0.0" />
<GradientStop Color="#FF333333"
Offset="0.5" />
<GradientStop Color="#FF111111"
Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush>
</Grid.Background>-->
<Grid.RowDefinitions>
<RowDefinition Height="37" />
<RowDefinition Height="274*" />
<RowDefinition Height="13*"/>
<RowDefinition Height="272*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Grid.Resources>
<ContextMenu x:Key="ListViewContextMenu">
<MenuItem x:Name="ContextRename"
Header="{x:Static Properties:Resources.RenameJob}"
Command="{Binding RenameJobCommand}" />
<MenuItem x:Name="ContextSetJobsiteAddress"
Header="{x:Static Properties:Resources.SetJobsiteAddress}"
Command="{Binding UpdateJobSiteAddressCommand}" />
<MenuItem x:Name="ContextSetCustomerAddress"
Header="{x:Static Properties:Resources.SetCustomerAddress}"
Command="{Binding UpdateCustomerInformationCommand}" />
<MenuItem x:Name="ContextSetContractorAddress"
Header="{x:Static Properties:Resources.SetContractorAddress}"
Command="{Binding UpdateContractorInformationCommand}" />
<MenuItem x:Name="ContextEditWorkOrderNumber"
Header="{x:Static Properties:Resources.EditWorkOrderNumber}"
Command="{Binding EditWorkOrderNumberCommand}" />
<Separator/>
<MenuItem x:Name="ExportToKML"
Header="{x:Static Properties:Resources.ExportToKML}"
Command="{Binding ExportToKMLCommand}"/>
</ContextMenu>
<Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
</Grid.Resources>
<DataGrid x:Name="JobListView"
AutoGenerateColumns="False"
ItemsSource="{Binding UnitStatusCollection, Mode=TwoWay}"
CanUserDeleteRows="False"
Style="{StaticResource JobGridViewStyle}"
SelectedItem="{Binding JobsListViewSelectedUnitInfo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Utility:DataGridColumnsBehavior.BindableColumns="{Binding DataGridColumns}"
ContextMenu="{StaticResource ListViewContextMenu}"
Margin="10,0,10,2"
Grid.Row="1"
SelectionMode="Single"
SelectionUnit="FullRow"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
RowStyle="{StaticResource DataGridRowStyle}"
CellStyle="{StaticResource DataGridCellStyle}"
AlternationCount="2"
CanUserResizeRows="False"
HorizontalGridLinesBrush="#d6d6d6"
VerticalGridLinesBrush="#d6d6d6"
Background="#EAEAEA"
>
<!--This is to allow double clicks to open a job in LWD 3x-->
<DataGrid.InputBindings>
<MouseBinding Gesture="LeftDoubleClick"
Command="{Binding OpenInLWD3xCommand}" />
<KeyBinding Key="Return"
Command="{Binding OpenInLWD3xCommand}" />
<KeyBinding Key="F5"
Command="{Binding RefreshCommand}"/>
</DataGrid.InputBindings>
<DataGrid.Resources>
<Converters:DoubleNanVisibilityConverter x:Key="DoubleNanVisibilityConverter" />
<Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
</DataGrid.Resources>
</DataGrid>
<Button Cursor="Hand"
Grid.ZIndex="0"
Margin="10,2,10,1"
Grid.Row="3"
x:Name="cmdMapImage"
Visibility="{Binding JobsListViewSelectedUnitInfo, Converter={StaticResource NullVisibilityConverter}}"
Style="{StaticResource MapButtonStyle}"
Command="{Binding ShowMapOnlineCommand}">
<Image x:Name="mapImage"
Source="{Binding DisplayedImage}"
Tag="{Binding JobId}"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<Rectangle Fill="#26598c"
Grid.ZIndex="1"
Margin="0,10,7,0"
Grid.Row="3"
Height="46"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Width="226"
RadiusY="3.667"
RadiusX="3.667"
Focusable="False"/>
<Button Grid.ZIndex="2"
Command="{Binding ScanForwardCommand}"
x:Name="scrollRightButton"
Margin="0,20,15,0"
HorizontalAlignment="Right"
Width="30"
Height="26"
VerticalAlignment="Top"
Grid.Row="3">
<Image x:Name="scrollRight"
Source="/Assets/Down-30px-tall.png"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<Button Grid.ZIndex="2"
Command="{Binding ScanBackwardCommand}"
x:Name="scrollLeftButton"
Margin="0,20,50,0"
RenderTransformOrigin="1,-0.617"
HorizontalAlignment="Right"
Width="30"
Height="26"
VerticalAlignment="Top"
Grid.Row="3">
<Image x:Name="scrollLeft"
Source="/Assets/Up-30px-tall.png"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality">
</Image>
</Button>
<ComboBox x:Name="ScanSizesComboBox"
Grid.ZIndex="2"
ItemsSource="{Binding ScanSizes}"
SelectedItem="{Binding SelectedScanSize, Mode=TwoWay}"
ToolTip="{Binding (Validation.Errors)[0].ErrorContent}"
Margin="0,20,85,0"
HorizontalAlignment="Right"
Width="61"
Height="26"
VerticalAlignment="Top"
Grid.Row="3" />
<Button x:Name="OpenLWD"
Grid.ZIndex="2"
Command="{Binding OpenInLWD3xCommand}"
Margin="0,20,150,0"
HorizontalAlignment="Right"
Width="75"
Height="26"
VerticalAlignment="Top"
Grid.Row="3"
Padding="0"
Background="#26598c">
<Image x:Name="openIn3x"
Source="/Assets/LWD-button.png"
Tag="{Binding JobId}"
Stretch="Fill"
VerticalAlignment="Center"
RenderOptions.BitmapScalingMode="HighQuality"
Height="27">
</Image>
</Button>
<DockPanel Grid.Row="0"
LastChildFill="False"
Grid.RowSpan="4">
<Menu x:Name="menu"
DockPanel.Dock="Top"
IsTabStop="False"
FontSize="13"
VerticalAlignment="Top"
Background="WhiteSmoke"
Height="27">
<MenuItem x:Name="FileMenu"
Header="{x:Static Properties:Resources.File}"
Background="Transparent" FontFamily="Arial">
<MenuItem x:Name="BluetoothUpload"
Header="{x:Static Properties:Resources.UploadBluetoothJob}"
IsEnabled="True"
Command="{Binding OpenLWD3xBluetoothCommand}" />
<MenuItem x:Name="FileUpload"
Header="{x:Static Properties:Resources.UploadLocalFile}"
IsEnabled="True"
Command="{Binding AddLocalJobCommand}" />
<Separator />
<MenuItem x:Name="FileLogout"
Header="{x:Static Properties:Resources.Logout}"
IsEnabled="True"
Command="{Binding LogoutCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
</MenuItem>
<MenuItem x:Name="ViewMenu"
Header="{x:Static Properties:Resources.View}"
Background="Transparent">
<MenuItem x:Name="ColumnOptions"
Header="{x:Static Properties:Resources.ColumnOptions}"
Background="Transparent"
Command="{Binding ShowColumnOptionsDialogCommand}" />
<MenuItem x:Name="DisplayUnits"
Header="{x:Static Properties:Resources.DisplayUnits}"
Background="Transparent"
Command="{Binding ShowUnitsSelectionCommand}" />
<Separator />
<MenuItem x:Name="ViewRefresh"
IsEnabled="True"
Header="Re_fresh"
Command="{Binding RefreshCommand}"
/>
<!--<MenuItem x:Name="ViewOptions" Header="_Options" />-->
</MenuItem>
<MenuItem x:Name="HelpMenu"
Header="{x:Static Properties:Resources.Help}"
Background="Transparent">
<MenuItem x:Name="HelpOpen"
Header="{x:Static Properties:Resources.OnlineHelp}" />
<Separator />
<MenuItem x:Name="HelpAbout"
Header="{x:Static Properties:Resources.About}"
Command="{Binding ShowAboutDialogCommand}" />
<MenuItem x:Name="DeleteUnits"
Header="Delete all Units"
Command="{Binding RemoveUnitsCommand}"/>
</MenuItem>
</Menu>
</DockPanel>
<GridSplitter x:Name="gridSplitter" Grid.Row="2" Width="Auto" MinHeight="5" MaxHeight="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0,4,0,4" />
</Grid>
</UserControl>
And here is the JobGridViewStyle:
<Style x:Key="JobGridViewStyle" TargetType="DataGrid">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Background" Value="WhiteSmoke" />
<Setter Property="SelectionMode" Value="Single" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="10,0,10,0" />
</Style>
I appreciate the help. I'm really not sure why, but the solution to my answer was to add
ShowsPreview="True"
to my GridSplitter. I have no idea why this would affect the functionality, but it fixed my issue.
For reference, I was looking at this page: How to: Resize Rows with a GridSplitter when I found out the solution.
Thanks again
Related
I need to glue content to window sides, would also like to add a gridsplitter to resize internal control separation, and the status bar creates whitespace.
The Grid won't resize vertically with the bottom of the window for instance.
Currently, I am yet unaware of the cause or resolution, starting to go blind on the code. I could use a second pair of eyes.
Change Heights into MinHeights, use Grid containers, etc.
Pretty much anything I could find and think of, including staring down the code...
<Window x:Class="Teachers_Lounge.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Teachers_Lounge"
mc:Ignorable="d"
Title="Teachers Lounge"
Height="625"
Width="1525"
MinHeight="625"
MinWidth="1525"
KeyDown="Window_KeyDown"
Closing="Window_Closing" Loaded="Window_Loaded">
<Window.Resources>
<DataTemplate x:Key="CalendarTemplate">
<Grid Margin="1">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="265" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<TextBlock FontWeight="Bold" Text="Name:" DockPanel.Dock="Left" Margin="5,0,10,0" />
<TextBlock Text="" />
<TextBlock Text="{Binding EventName}" Foreground="Green" FontWeight="Bold" />
</DockPanel>
<DockPanel Grid.Row="1" Grid.Column="0">
<TextBlock FontWeight="Bold" Text="Date:" Foreground="DarkGray" DockPanel.Dock="Left" Margin="5,0,5,0" />
<TextBlock Text="{Binding EventDateTime}" />
</DockPanel>
<Grid Grid.Column="1" Grid.RowSpan="2" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="-5,0,5,0">
<Button x:Name="EditEvent_Button" Width="40" Height="15" Margin="0,5,0,0" VerticalAlignment="Top" BorderThickness="0" Background="LightGray" CommandParameter="{Binding}" Command="{Binding ElementName=Window, Path=OnClickEditEvent}" Click="EditEvent_Button_Click">
<TextBlock Margin="0, -2">Edit</TextBlock>
</Button>
<Button x:Name="DeleteEvent_Button" Width="40" Height="15" Margin="0,20,0,5" VerticalAlignment="Bottom" BorderThickness="0" Background="LightGray" CommandParameter="{Binding}" Command="{Binding ElementName=Window, Path=OnClickDeleteEvent}" Click="DeleteEvent_Button_Click">
<TextBlock Margin="0, -2">Delete</TextBlock>
</Button>
</Grid>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid MinHeight="586" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="360" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox x:Name="DateAndTime" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Height="30" Margin="10,10,0,0" TextWrapping="Wrap" Text="dddd dd mmmm HHh" VerticalAlignment="Top" Width="350" FontSize="20" IsEnabled="False"/>
<TextBox x:Name="Topic" Grid.Row="0" Grid.Column="1" Margin="10,10,77,10" TextWrapping="Wrap" Text="Topic" FontSize="20" FontWeight="Bold" KeyDown="Topic_KeyDown" LostFocus="Topic_LostFocus" />
<Button x:Name="Settings_Button" Grid.Column="1" Margin="0,10,10,10" FontWeight="Bold" Click="Settings_Button_Click" HorizontalAlignment="Right" Width="62">Settings</Button>
<Grid Grid.Row="1" Grid.Column="0"
Margin="10,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="489*" />
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<Menu BorderThickness="1 1 1 0" BorderBrush="Black">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="New Event" Click="NewReplacement_Click" />
</Menu>
<ListBox x:Name="CalendarList" Grid.Row="1"
BorderThickness="1 0 1 1" BorderBrush="Black"
HorizontalAlignment="Left" MinWidth="350" MinHeight="485" VerticalAlignment="Top"
ItemsSource="{Binding Tables[0]}" ItemTemplate="{StaticResource CalendarTemplate}" KeyDown="CalendarList_KeyDown"/>
</Grid>
<Grid Grid.Row="1" Grid.Column="1"
HorizontalAlignment="Left" MinHeight="485" MinWidth="1072" VerticalAlignment="Top" Margin="10,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu BorderThickness="1 1 1 0" BorderBrush="Black">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="🠜" Click="ExcelPreviousDate_Click" />
<MenuItem Header="🡄" Click="ExcelPreviousWeek_Click" />
<MenuItem x:Name="ExcelActiveTimewindow" Header="Week XX, Date dd-MM-yy" IsEnabled="False" />
<MenuItem Header="🡆" Click="ExcelNextWeek_Click" />
<MenuItem Header="🠞" Click="ExcelNextDate_Click" />
<Separator />
<MenuItem Header="New Replacement" Click="NewReplacement_Click" />
<MenuItem Header="Delete Replacements" HorizontalAlignment="Right" Click="DeleteReplacements_Click" />
</Menu>
<DataGrid Name="ExcelDataView" Grid.Row="1"
BorderThickness="1 0 1 1" BorderBrush="Black"
AutoGenerateColumns="False"
ColumnWidth="*"
RowBackground="WhiteSmoke"
Background="LightBlue"
CanUserAddRows="False"
BeginningEdit="ExcelDataView_BeginningEdit"
CellEditEnding="ExcelDataView_CellEditEnding"
RowEditEnding="ExcelDataView_RowEditEnding"
SelectionChanged="ExcelDataView_SelectionChanged"
MinWidth="1077" MinHeight="485" HorizontalAlignment="Left" VerticalAlignment="Top">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<EventSetter Event="Click" Handler="OnExcelHeaderClicked" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Time" Binding="{Binding TimeText, Mode=TwoWay}" Width="70" CanUserSort="False" />
<DataGridTextColumn Header="Replaced User" Binding="{Binding ReplacedUser, Mode=TwoWay}" Width="140" CanUserSort="False" />
<DataGridTextColumn Header="Replacement User" Binding="{Binding ReplacementUser, Mode=TwoWay}" Width="140" CanUserSort="False" />
<DataGridTextColumn Header="Class" Binding="{Binding Class, Mode=TwoWay}" Width="170" CanUserSort="False" />
<DataGridTextColumn Header="Location" Binding="{Binding Location, Mode=TwoWay}" Width="170" CanUserSort="False" />
<DataGridTextColumn Header="Info" Binding="{Binding AdditionalInfo, Mode=TwoWay}" CanUserSort="False" />
<DataGridCheckBoxColumn Header="Mark" Binding="{Binding Marked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CanUserSort="False" Width="50">
<DataGridCheckBoxColumn.CellStyle>
<Style>
<EventSetter Event="CheckBox.Checked" Handler="OnExcelDeleteColumnChecked"/>
<EventSetter Event="CheckBox.Unchecked" Handler="OnExcelDeleteColumnUnchecked"/>
</Style>
</DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
<Menu Grid.Row="3" Grid.ColumnSpan="2"
BorderThickness="0 1 0 0" BorderBrush="Black" IsEnabled="False"
VerticalAlignment="Bottom" Height="20">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem MinWidth="1111" BorderThickness="0">
<MenuItem.Header>
<TextBlock x:Name="StatusbarMessage"
HorizontalAlignment="Left" VerticalAlignment="Center"
TextAlignment="Left" />
</MenuItem.Header>
</MenuItem>
<MenuItem BorderThickness="0"
HorizontalAlignment="Right" HorizontalContentAlignment="Right" Width="350" >
<MenuItem.Header>
<TextBlock x:Name="StatusbarInfo"
VerticalAlignment="Center" Width="335"
TextAlignment="Right" />
</MenuItem.Header>
</MenuItem>
</Menu>
</Grid>
</Window>
A proper layout that resizes as it should is what I'd expect.
Some weird behavior and glue-ing are what is happening though.
I need to create a custom style for MenuItem with a set of ControlTemplate per each MenuItem Role. So, I decided to use this approach from msdn
But, there's one problem - I want to get the same appearance in Popup.
Unfortunately, the appearance is different like on the picture below:
Example of code:
<Window x:Class="ExporerSubMenu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExporerSubMenu"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="1000">
<Window.Resources>
<!-- Copy all styles for MenuItem ControlTemplate and Brushes -->
<!-- https://msdn.microsoft.com/fr-fr/library/ms747082(v=vs.85).aspx -->
</Window.Resources>
<Grid Background="LightBlue">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBox Text="Local (right click)" FontSize="16" Grid.Column="0">
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Restore...">
<MenuItem Header="to desktop" />
<MenuItem Header="to another folder" />
<MenuItem Header="db schema and data..." />
</MenuItem>
<MenuItem Header="to .bac file">
<MenuItem Header="to desktop" />
<MenuItem Header="to another folder" />
</MenuItem>
<MenuItem Header="to db files">
<MenuItem Header="to desktop" />
<MenuItem Header="to another folder" />
</MenuItem>
<MenuItem Header="Export data">
<MenuItem Header="db schema to desktop" />
<MenuItem Header="db schema and data..." />
</MenuItem>
<MenuItem Header="Remove" />
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
</Grid>
</Window>
Now, I have only one solution - to draw rectangles (from Blend)
<Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">
<Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
<Border x:Name="SubMenuBorder" BorderBrush="#FF959595" BorderThickness="1" Background="WhiteSmoke">
<ScrollViewer x:Name="SubMenuScrollViewer" Margin="1,0" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
<Grid x:Name="Grid2" RenderOptions.ClearTypeHint="Enabled">
<Canvas x:Name="Canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect" Fill="WhiteSmoke" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
</Canvas>
<Rectangle x:Name="Rectangle" Fill="#FFF1F1F1" HorizontalAlignment="Left" Margin="1,2" RadiusY="2" RadiusX="2" Width="28"/>
<Rectangle x:Name="Rectangle1" Fill="#FFE2E3E3" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>
<Rectangle x:Name="Rectangle2" Fill="White" HorizontalAlignment="Left" Margin="30,2,0,2" Width="1"/>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</ScrollViewer>
</Border>
</Themes:SystemDropShadowChrome>
</Popup>
Is there any another solution to solve this ?
I have a collection of objects to which I have created a ScrollViewer to show. For each Object, the data is displayed in a grid to which I have added a context menu so that when the user right clicks the grid, they can alter properties of the object. I cannot figure out how to know which object has been right clicked.
In the code below, how would I know which "VoltageMonitor" was right clicked when it reaches the callback for MenuItem "TurnOff"?
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Margin="0,0,0,15">
<ItemsControl Name="icVoltageMonitorsPanel" ItemsSource="{Binding AppMonitors.VoltageMonitors, Mode=TwoWay}" Grid.ColumnSpan="2" Padding="0" Margin="0" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="local:VoltageMonitor">
<Grid Height="130" Name="grdIndicator" Width="200" MinWidth="200" MinHeight="130">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Edit Format..." />
<MenuItem Header="Turn off" Click="MenuItem_Click" DataContext=""/>
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="30*" />
<RowDefinition Height="25*" />
<RowDefinition Height="25*" />
<RowDefinition Height="25*" />
<RowDefinition Height="25*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="133*" />
<ColumnDefinition Width="67*" />
</Grid.ColumnDefinitions>
Assuming you have defined an ICommand in your viewmodel, you can do it like this:
<ItemsControl ...>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="local:VoltageMonitor">
<Grid ..>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Edit Format..." />
<MenuItem Header="Turn off"
CommandParameter="{Binding}"
Command="{Binding RelativeSource=
{RelativeSource Mode=FindAncestor,
AncestorType={x:Type ItemsControl}},
Path=DataContext.TurnOffCommand}"/>
</ContextMenu>
</Grid.ContextMenu>
I have a WPF Application with a Ribbon Control. I want to add a ComboBox, to show the logged in user next to the help button. But when I try to add the ComboBox, it is created as a Tab.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Ribbon x:Name="RibbonWin" SelectedIndex="0" Margin="0,0,0,113">
<Ribbon.HelpPaneContent>
<RibbonButton SmallImageSource="Images\help.png"></RibbonButton>
</Ribbon.HelpPaneContent>
<RibbonComboBox>
<ComboBoxItem Content="Test1"/>
</RibbonComboBox>
<RibbonTab Header="Home" KeyTip="H" Margin="0,0,0,-1" >
<RibbonGroup x:Name="ClipboardGroup" Header="Clipboard">
<RibbonMenuButton LargeImageSource="Images\paste.jpg" Label="Paste" KeyTip="V">
<RibbonMenuItem ImageSource="Images\paste.jpg" Header="Keep Text Only" KeyTip="T"/>
<RibbonMenuItem ImageSource="Images\paste.jpg" Header="Paste Special..." KeyTip="S"/>
</RibbonMenuButton>
<RibbonButton SmallImageSource="Images\cut.jpg" Label="Cut" KeyTip="X" />
<RibbonButton SmallImageSource="Images\copy.jpg" Label="Copy" KeyTip="C" />
</RibbonGroup>
<RibbonGroup x:Name="Questions" Header="Questions And Answers">
<RibbonMenuButton LargeImageSource="Images\Question.jpg" Label="Questions" KeyTip="V">
<RibbonMenuItem ImageSource="Images\paste.jpg" Header="Add Question" KeyTip="T"/>
<RibbonMenuItem ImageSource="Images\paste.jpg" Header="Paste Special..." KeyTip="S"/>
</RibbonMenuButton>
<RibbonButton SmallImageSource="Images\Save.jpg" Label="Save" KeyTip="X" />
<RibbonButton SmallImageSource="Images\Add.jpg" Label="Add" KeyTip="C" />
</RibbonGroup>
</RibbonTab>
<RibbonTab Header="Insert" KeyTip="I">
</RibbonTab>
<RibbonTab Header="PageLayout" KeyTip="L">
</RibbonTab>
</Ribbon>
</Grid>
Also is there a way to remove the the Application Menu ComboBox on the left that is created by default.
Put a RibbonApplicationMenu into the ApplicationMenu-property and set its Visibility to 'Collapsed'. This will not remove the application menu, but at least it is not longer visible. There is not other way to hide it.
The ComboBox must be inserted into a RibbonTab, so a RibbonTab will be created implicitly if you do not specify anyone.
The following example demonstrates how to hide the application menu and insert a combo box:
<Ribbon>
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu Visibility="Collapsed"></RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab>
<RibbonGroup>
<RibbonComboBox></RibbonComboBox>
</RibbonGroup>
</RibbonTab>
</Ribbon>
I got it from my friend,
this might help you
Create your own template and add it to Ribbon HelpPaneContentTempalte
<Ribbon.HelpPaneContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="24">
<ToggleButton x:Name="btn" >
<TextBlock Text="Operator"/>
</ToggleButton>
<Popup IsOpen="{Binding IsChecked, ElementName=btn}" x:Name="Popup" StaysOpen="False" Placement="Bottom"
PlacementTarget="{Binding ElementName=btn}" Height="120" Width="150" HorizontalOffset="-90" >
<Popup.Resources>
<Style x:Key="LinkButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock>
<ContentPresenter />
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Blue" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Popup.Resources>
<Border BorderBrush="Gray" BorderThickness="2" Background="White" >
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Height="50">
<Image Source="Images\UserPhoto.png" Height="30"/>
<StackPanel VerticalAlignment="Center">
<TextBlock Text="Operator" FontSize="16" Margin="10,0,0,0"/>
<TextBlock Text="Operator#xxx.com" FontSize="10" Foreground="DarkGray" Margin="10,0,0,0"/>
</StackPanel>
</StackPanel>
<Separator Background="LightGray"/>
<StackPanel Height="30">
<Button x:Name="btnAccountSettings" Content="Account Settings" Style="{StaticResource LinkButton}" Width="100" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"></Button>
</StackPanel>
<Separator Background="LightGray"/>
<StackPanel Height="30">
<Button x:Name="btnSwitchAccount" Content="Switch Account" Style="{StaticResource LinkButton}" Width="100" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"></Button>
</StackPanel>
</StackPanel>
</Border>
</Popup>
<ContentPresenter Content="{TemplateBinding Property= ContentControl.Content}" />
</StackPanel>
</DataTemplate>
</Ribbon.HelpPaneContentTemplate>
<Ribbon.HelpPaneContent>
<RibbonButton x:Name="btnHelp" SmallImageSource="Images\help.png" />
</Ribbon.HelpPaneContent>
I'm new to C# programming so here goes..
I'm trying to write an electronic scrapbook application as a present but I've come unstuck - my application currently shows the first xml record but I don't know how to use the next button to go to the next record. I've tried experimenting with arrays and arraylists but I can't seem to get anywhere near what I'm looking for. Any help would be hugely appreciated :-)
I'll include my XML and XAML code below but I'll leave out the C# code as it'll make my post too long. Apologies if any of the code below is irrelevant to you:
XAML:
<Grid>
<Grid.DataContext>
<XmlDataProvider Source="Data/Memories.xml" XPath="/Memories/Memory" />
</Grid.DataContext>
<DockPanel Height="22" Name="dockPanel1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Width="Auto">
<Menu Height="24" Name="menu1" Width="Auto" DockPanel.Dock="Top" VerticalAlignment="Top">
<MenuItem Header="_File" >
<MenuItem Header="Add _New Memory" Name="newMemory" Click="newMemory_Click" />
<MenuItem Header="_Edit this Memory" Name="editMemory" Click="editMemory_Click" />
<MenuItem Header="_Delete this Memory" Name="deleteMemory" Click="deleteMemory_Click" />
<MenuItem Header="_Save Changes" Name="saveMemory" Click="saveMemory_Click" />
<Separator/>
<MenuItem Header="E_xit" Name="exit" Click="exit_Click" />
</MenuItem>
<MenuItem Header="_Edit" />
<MenuItem Header="_Help" >
<MenuItem Header="_About muh program" Name="about" Click="about_Click" />
</MenuItem>
</Menu>
</DockPanel>
<Button Content="<" Margin="-70,32,0,0" Name="previousButton" Height="22" Width="20" VerticalAlignment="Top" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfTrue}}" />
<Button Content=">" Height="22" Margin="70,32,0,0" Name="nextButton" Width="20" VerticalAlignment="Top" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfTrue}}" />
<Button Content="?" Margin="0,32,0,0" Name="RandomButton" Height="22" Width="40" VerticalAlignment="Top" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfTrue}}" />
<TextBlock Height="30" Width="300" Margin="0,62,0,419" TextAlignment="Center" Text="{Binding XPath=#Title}" FontSize="15" FontWeight="Bold" Name="memoryTitle" />
<TextBlock Height="30" Width="300" Margin="0,84,0,397" TextAlignment="Center" Text="{Binding XPath=./Date}" FontSize="12" FontWeight="Normal" Name="memoryDate" Panel.ZIndex="1" />
<TextBlock Height="375" HorizontalAlignment="Right" Margin="0,116,26,20" Name="textOutput" Width="300" TextWrapping="Wrap" TextAlignment="Center" Background="White" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfTrue}}">
<TextBlock.Text>
<Binding XPath="./Blurb" />
</TextBlock.Text>
</TextBlock>
<TextBox HorizontalAlignment="Right" Margin="0,116,26,20" Name="textInput" Height="375" Width="300" TextWrapping="Wrap" AcceptsReturn="True" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfNotTrue}}" />
<Image Height="375" HorizontalAlignment="Center" Margin="-326,94,0,0" Name="imgPhoto" Stretch="Uniform" VerticalAlignment="Center" Width="500" ClipToBounds="False" AllowDrop="False" Source="{Binding XPath=ImageFile}" />
<Image Height="375" HorizontalAlignment="Center" Margin="-326,94,0,0" Name="imgPhotoNew" Stretch="Uniform" VerticalAlignment="Center" Width="500" ClipToBounds="False" AllowDrop="False" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfNotTrue}}" />
<Button Content="Done" Height="22" Width="40" Margin="463,32,375,0" Name="doneMemoryButton" VerticalAlignment="Top" Click="doneMemoryButton_Click" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfNotTrue}}" />
<Button Content="Select Photo" Height="22" Width="75" Margin="377,32,427,0" Name="selectPhotoButton" VerticalAlignment="Top" HorizontalAlignment="Center" Click="selectPhotoButton_Click" Visibility="{Binding IsEnabled, ElementName=newMemory, Converter={StaticResource VisibleIfNotTrue}}" />
</Grid>
XML:
<Memories>
<Memory Title="1 Year - Howard Jones!" ID="1">
<ImageFile>Data/Images/01.jpg</ImageFile>
<Blurb>We saw Howard Jones perform!!</Blurb>
<Date>06/11/2010</Date>
</Memory>
<Memory Title="Ski Holiday" ID="2">
<ImageFile>Data/Images/02.jpg</ImageFile>
<Blurb>Our skiing holiday in Flaine!</Blurb>
<Date>29/11/2010</Date>
</Memory>
<Memory Title="Stinksy's Birthday: Ice Bar!" ID="3">
<ImageFile>Data/Images/03.jpg</ImageFile>
<Blurb>Absolut Ice Bar</Blurb>
<Date>19/12/2010</Date>
</Memory>
</Memories>
I will not work through that code but i can give you a simple example of how to do this:
<Window.Resources>
<XmlDataProvider x:Key="data" Source="Data/Memories.xml" XPath="/Memories/Memory" />
<CollectionViewSource x:Key="dataCvs" Source="{StaticResource data}" />
</Window.Resources>
<StackPanel>
<ContentControl Content="{Binding Source={StaticResource dataCvs}}">
<ContentControl.ContentTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding XPath=ImageFile}" />
<TextBlock Text="{Binding XPath=Blurb}" />
<TextBlock Text="{Binding XPath=Date}" />
</StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
<Button Content="Previous" Click="Previous_Click" Tag="{StaticResource dataCvs}" />
<Button Content="Next" Click="Next_Click" Tag="{StaticResource dataCvs}" />
</StackPanel>
The ContentControl binds to the CurrentItem of the view on top of the memories collection, i pass the CollectionViewSource to the Buttons so i can change the current item on click. (Normally you should use a Command and pass it as CommandParameter instead, that is cleaner)
private void Next_Click(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var cvs = (CollectionViewSource)button.Tag;
cvs.View.MoveCurrentToNext();
}
private void Previous_Click(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var cvs = (CollectionViewSource)button.Tag;
cvs.View.MoveCurrentToPrevious();
}