White space between menu and window - c#

Using the menu control in a xaml window, I have this annoying white space between the window border and the docking panel.
The menu itself is inside a stackpanel:
<Window x:Class="COZView.Shell"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sc="clr-namespace:COZView.StaticContent"
xmlns:ve="clr-namespace:COZView.View_Edit"
Title="COZView" Width="1024" Height="800" Icon="/COZView;component/Images/COZView.png"
Loaded="OnLoaded" IsVisibleChanged="isVisibleChanged" Closing="OnClosing">
<Grid x:Name="ShellRegion">
<StackPanel Height="Auto" Orientation="Vertical">
<Menu x:Name="menu">
<!-- MENU ITEMS REMOVED -->
</Menu>
<Grid x:Name="DockingRegion" >
<ad:DockingManager x:Name="DockManager">
<ad:ResizingPanel>
<ad:DocumentPane Margin="0,0,0,0">
<sc:StartPage Title="Home Page" VerticalContentAlignment="Stretch"
onProjectOpenFail="StartPage_onProjectOpenFail"
onProjectOpenSuccess="StartPage_onProjectOpenSuccess"
onProjectCreateSuccess="StartPage_onProjectCreateSuccess"
onProjectCreateFail="StartPage_onProjectCreateFail"/>
</ad:DocumentPane>
<ad:DockablePane ad:ResizingPanel.ResizeWidth="300" x:Name="ExplorerPane" FontSize="14" FontWeight="Bold">
<sc:AboutTab x:Name="about" Title="About" FontSize="14" FontWeight="Bold"/>
<sc:ProcessExplorer x:Name="pxProcessExplorer" Title="Process Explorer" FontSize="14"/>
<sc:DataExplorer x:Name="adDataExplorer" Title="Data Explorer" FontSize="14"/>
<!--<sc:UREPExplorer x:Name="adUREPExplorer" Title="UREP Custom Navigation" FontSize="14" Visibility="Hidden"/>-->
</ad:DockablePane>
</ad:ResizingPanel>
</ad:DockingManager>
</Grid>
</StackPanel>
</Grid>
How do i remove the white space? Do I have to surrond it in something? Should the menu be in a different container?

Its just the default menu style where Background is defined as
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFF6F6F6" Offset="0.25" />
<GradientStop Color="#FFEAE8E8" Offset="0.25" />
<GradientStop Color="#FFDCD9D9" Offset="0.8" />
<GradientStop Color="#FFFFFFFF" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
Define a different background if you dont like the #FFFFFFFF bottom line.

Related

How to put my controls within wizard pages?

I am using WPF Toolkit from xceed because I want to create a wizard in my WPF application. This seemed like a good option. Their sample wizard works but I'm unsure how I add my own controls to a wizard page. The documentation is quite limited and only really shows how to change the presentation of the wizard, rather than the behaviour.
When I move control definitions within the .xaml file to be inside the wizard, it says that Wizard should only contain WizardPages. Is it something I need to do in the code behind instead? You might have guessed that this is my first go with WPF.
Code below. I want the border & stackpanel at the bottom to only show up in one of the wizard pages. Currently they just sit on top of the wizard
<Window xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
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:myApp"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="myApp.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="1000" MinWidth="5">
<Window.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="LightGray" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Window.BorderBrush>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="767*"/>
<ColumnDefinition Width="199*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<xctk:Wizard FinishButtonClosesWindow="True">
<xctk:WizardPage x:Name="IntroPage"
Title="Welcome to my Wizard"
Description="This Wizard will walk you though how to do something." />
<xctk:WizardPage x:Name="Page1" PageType="Interior"
Title="Page 1"
Description="This is the first page in the process."
NextPage="{Binding ElementName=Page2}"
PreviousPage="{Binding ElementName=IntroPage}"/>
<xctk:WizardPage x:Name="Page2" PageType="Interior"
Title="Page 2"
Description="This is the second page in the process"/>
<xctk:WizardPage x:Name="LastPage" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True"/>
</xctk:Wizard>
<Border Background="GhostWhite" BorderBrush="Silver" BorderThickness="1" CornerRadius="3,3,3,3" Grid.Column="1">
<StackPanel Margin="10">
<Button Content="Button 1"/>
<Button Content="Button 2"/>
<TextBox Controls:TextBoxHelper.Watermark="This is a textbox" />
<Controls:ToggleSwitch Header="Click me" />
</StackPanel>
</Border>
</Grid>
You could put the Border element inside the <xctk:WizardPage> element, e.g.:
<xctk:WizardPage x:Name="LastPage" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True">
<Border Background="GhostWhite" BorderBrush="Silver" BorderThickness="1" CornerRadius="3,3,3,3" Grid.Column="1">
<StackPanel Margin="10">
<Button Content="Button 1"/>
<Button Content="Button 2"/>
<TextBox />
</StackPanel>
</Border>
</xctk:WizardPage>

How to show a popup on datagrid button click in wpf c#?

I have a common popup in my wpf window and I have a button in the datagrid as well. What I want is to open the popup when the button is clicked. The popup should be independent to each button click. For example, let's say that I have two rows in the datagrid. When I click on the first button popup should appear,then I do some changes to that popup and close it. Now I click the second button it should open a new popup instead of the changes I made before. I'm using a common popup for this. Please anyone tell me is it possible to handle my requirement with common popup window?
XAML
<Popup x:Name="popUpServer" IsOpen="False" Placement="MousePoint" >
<Border Background="#FFEFF2F3" BorderBrush="Black" BorderThickness="1" Width="229" Height="145">
<StackPanel Orientation="Horizontal" Margin="0,0,0,-17">
<Grid Width="227" Margin="0,0,0,10">
<GroupBox Header="Configuration" HorizontalAlignment="Left" Margin="9,6,-9,0" VerticalAlignment="Top" Height="125" Width="211">
<Grid>
<Label Content="Auto Restart" HorizontalAlignment="Left" Margin="10,6,0,0" VerticalAlignment="Top"/>
<ToggleSwitch:HorizontalToggleSwitch x:Name="tsAutoRestart" HorizontalAlignment="Left" Margin="97,10,0,0" VerticalAlignment="Top" Width="46" ThumbSize="22" Height="21" RenderTransformOrigin="3.522,1.048">
<ToggleSwitch:HorizontalToggleSwitch.UncheckedBackground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFC80000" Offset="1"/>
<GradientStop Color="#FF0A0A0A" Offset="0.853"/>
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.UncheckedBackground>
<ToggleSwitch:HorizontalToggleSwitch.CheckedBackground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#000000" />
<GradientStop Color="#000000" Offset="1" />
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.CheckedBackground>
<ToggleSwitch:HorizontalToggleSwitch.ThumbBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFD6D4D4" />
<GradientStop Color="#FFD6D4D4" Offset="1" />
<GradientStop Color="#FFD6D4D4" Offset="0.02" />
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.ThumbBrush>
</ToggleSwitch:HorizontalToggleSwitch>
<ComboBox x:Name="cbDuration" HorizontalAlignment="Left" VerticalAlignment="Top" Width="92" Margin="97,40,0,0">
<ComboBoxItem Content="30 Minutes"/>
<ComboBoxItem Content="1 Hours"/>
<ComboBoxItem Content="2 Hours"/>
</ComboBox>
<Label Content="After" HorizontalAlignment="Left" VerticalAlignment="Top" Width="83" Margin="9,36,0,0"/>
<Button x:Name="btnApply" Content="Apply" HorizontalAlignment="Left" Margin="125,75,0,0" VerticalAlignment="Top" Width="64" Click="BtnApply_Click"/>
</Grid>
</GroupBox>
</Grid>
</StackPanel>
</Border>
</Popup>
Datagrid
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="txtServerInfo" Click="TxtServerInfo_Click" Height="23" Width="28">
<Button.Background>
<ImageBrush ImageSource="img.png"/>
</Button.Background>
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Code behind file
private void TxtServerInfo_Click(object sender, RoutedEventArgs e)
{
popUpServer.IsOpen = true;
}
If you want to use a common popup means better create a popup in a separate user control.then for a button click you can create a new object for the user control and then open the popup by using the user controls object.then the values inside the popup will be independent of the previous button click.
please try the next solution; combine your popup with the button into a separate user control, in that way you can trigger the popup opening based on the button click, and for each button click there will be it's(button) own popup opened there. When you combine the popup and the button together they will have the same data context, thus you will have no problem to make a binding, from the other hand if you want a different data contexts for these controls you can support the user with two dependency properties form that a combined user control.
I'll glad to help if you will have problems with the code, let me know about that.
Regards.

C# Xaml ListBox Template Add in c#

I did some research about the listbox but i didnt understand how to solve my problem.
I have a Listbox in my xaml page and i want to add now a listviewitem using the Template (so i get toggle button and so on) not in xaml and with the help of c#. How do i do this? Thx for your help
<ListBox x:Name="Listbox" Background="Red">
<ListBox.ItemTemplate >
<DataTemplate>
<Grid x:Name="TemplateGrid">
<ToggleSwitch x:Name="Toggle" Foreground="Black">
<ToggleSwitch.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</ToggleSwitch.Background>
</ToggleSwitch>
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Width="26" x:Name="Text" Foreground="Black">Test</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
The listbox will use the template automatically. From your code, just call Listbox.Items.Add(obj). One thing to note though - in your data template I don't see that you are specifying a datatype for your data template to target, so it will use a generic display by calling ToString() on your object.

Finding the x:Name in Xaml from C#

From getting a little help, I managed to make the window only open once, now I want to change the window to a page. When I do this obviously .Show(); and also .Close(); have no extension method.
Now I added a frame to my Generic page (As this will be on all forms):
<Frame x:Name="FrameNavigate" HorizontalAlignment="Left" Height="300" Margin="1296,52,0,0" VerticalAlignment="Top" Width="300" NavigationUIVisibility="Hidden"/>
And I put the x:Name"FrameNavigate" in the XAML. In the code behind the Generic page, I wanted to add this piece of code to open the page up on the frame.
private void btnHelp_Click(object sender, RoutedEventArgs e)
{
if (help != null)
{
help.Close();
help = null;
}
else
{
help = new xamlHelp();
FrameNavigate.Navigate(new xamlHelp());
}
}
But It says that FrameNavigate doesn't exist?
EDIT:
<Style TargetType="{x:Type local:Master}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Master}">
<StackPanel>
<Canvas Height="50" Margin="0,0,0,0" HorizontalAlignment="Stretch" FlowDirection="RightToLeft">
<Canvas.Background>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
<GradientStop Color="#FFB3DDF2" Offset="1.0"/>
<GradientStop Color="#FFD6E9F4" Offset="0.0"/>
</LinearGradientBrush>
</Canvas.Background>
<Button x:Name="btnHelp" Content="Help" Click="btnHelp_Click" Foreground="#FF7E8385" FontFamily="Calibri" FontSize="18" Margin="110,10,0,0" Height="30" Width="70" Style="{x:Null}" BorderBrush="Transparent" Background="Transparent" Cursor="Hand"/>
<GridSplitter Height="30" Width="1" Margin="95,10,0,0" Background="Gray"/>
<Button x:Name="btnSettings" Content="Settings" Foreground="#FF7E8385" FontFamily="Calibri" FontSize="18" Margin="10,10,0,0" Click="btnSettings_Click" Height="30" Width="70" Style="{x:Null}" BorderBrush="Transparent" Background="Transparent" Cursor="Hand"/>
</Canvas>
<Canvas Width="350" Height="850" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Left" FlowDirection="RightToLeft" DockPanel.Dock="Bottom">
<Canvas.Background>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
<GradientStop Color="#FFD6E9F4" Offset="1.0"/>
<GradientStop Color="White" Offset="0.0"/>
</LinearGradientBrush>
</Canvas.Background>
<Frame x:Name="FrameNavigate" HorizontalAlignment="Left" Height="300" Margin="1296,52,0,0" VerticalAlignment="Top" Width="300" NavigationUIVisibility="Hidden"/>
</Canvas>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
EDIT:
I have this code which has got no errors, but when you click the button nothing appears?
Master master = ((Button)sender).TemplatedParent as Master;
Frame frame = (Frame)master.Template.FindName("FrameNavigate",master);
frame.Navigate(new xamlHelp());
Since Frame exists in ControlTemplate, you can't access it directly like this from code behind.
Ask template to get that for you by using FrameworkTemplate.FindName method.
Also you need to get Master control (obviously to get template of Master control) which you can get via accessing TemplatedParent of sender button.
This is how you need to do it:
Master master = ((Button)sender).TemplatedParent as Master;
Frame frame = (Frame)master.Template.FindName("FrameNavigate", master);
frame.Navigate(new xamlHelp());
UPDATED:
The Navigate(TypeName) method takes a Type object!
Frame frame = (Frame)this.FindName("FrameNavigate");
frame.Navigate(typeof(xamlHelp)); //frame.Navigate(help);
Have a look at:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.frame.navigate.aspx
and at:
http://msdn.microsoft.com/en-us/library/windows/apps/hh771188.aspx
ps. Note you are not using your help variable in you else code block.

Scrollviewer blocking events

the thing i am battling today is the scrollviewer, and the fact that it blocks my events.SO..here's some xaml:
<ScrollViewer x:Name="scrollv" Panel.ZIndex="15" Margin="8,65.5,0,22" VerticalScrollBarVisibility="Visible" Height="392.5" Background="White" IsHitTestVisible="False">
<Grid x:Name="listaintrebari" Height="Auto" Width="301.5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="White" >
</Grid>
</ScrollViewer>
So the thing is: on the grid which is inside the scrollviewer i programaticly add the questions UserControl...which incidentaly has a button with a click event.My problem is that i cant manage to click the button..it's like the scrollviewer is acting like an invisible shield to protect the usercontrol and the button from the evil Mouse!
Any help apreciated!
EDIT:(this is my questions Usercontrol)
<UserControl
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:eHelper_v3"
mc:Ignorable="d"
x:Class="eHelper_v3.questions"
x:Name="IntrebareControl" Width="330.641" Margin="0" MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"
>
<Grid x:Name="LayoutRoot" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="0,0,13,0" Height="90" >
<Rectangle x:Name="rect" Panel.ZIndex="20" Height="90" Stroke="#FF0975A3" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#1404BFD8" Offset="0.004"/>
<GradientStop Color="#1300A7FF" Offset="0.996"/>
<GradientStop Color="#2B0F82CC" Offset="0.459"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="imagine" HorizontalAlignment="Left" Margin="8,8,0,8" Width="126.667" Stretch="Fill" MouseLeftButtonDown="imagine_MouseLeftButtonDown" />
<TextBlock x:Name="textul" Margin="138.667,8,8,22.5" TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" FontSize="9.333"/>
<Label x:Name="status" Content="Status" Height="22" Margin="127,0,100,0.5" VerticalAlignment="Bottom" FontSize="9.333" Background="#00894848" Foreground="Red"/>
<Button x:Name="raspundeBtn" Content="Raspunde" HorizontalAlignment="Right" Height="18" Margin="0,0,8,4.5" VerticalAlignment="Bottom" Width="50.974" FontSize="9.333" Click="raspundeBtn_Click"/>
</Grid>
REEDITED ...wrong code inserted...kinda sleepy over here
Perhaps, some control ist in front of your button. To click "through" a control you can use
IsHitTestVisible="false"
Can you post your CommentThat ?
#after your edit:
It seems like your RichTextBox and that FlowDocument lies over the Button.
Add your Button as the last child of your Grid.
The user control is handling the left mouse button so the click does not get to the content.
MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"
Does that event get raised?
Just in case someone also has problems with the ScrollViewer preventing mouse button events from firing, I solved this by setting a ZIndex for the corresponding UIElement:
<TextBlock Text="Hello World!" Panel.ZIndex="2" MouseLeftButtonUp="TextBlockMouseLeftButtonUp"/>

Categories