How to align text in a menu item? I tried with vertical content alignment, but didn't work. It worked only for Button and TextBox.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="652" Width="1054">
<Grid HorizontalAlignment="Center" Height="617" Width="1041">
<Grid.Background>
<ImageBrush ImageSource="/WpfApplication4;component/Images/hp-colorful-books-hd-105609.jpg" />
</Grid.Background>
<ToolBarPanel Height="42" HorizontalAlignment="Left" Margin="1,91,0,0" Name="toolBarPanel1" VerticalAlignment="Top" Width="1043" Background="#FFEEEEEE" />
<Grid Height="472" HorizontalAlignment="Left" Margin="1,133,0,0" Name="grid1" VerticalAlignment="Top" Width="213" Background="#FFF0F0F0">
<MenuItem Height="40" Name="menuItem1" Width="209" BorderBrush="{x:Null}" Header="Folder" FontSize="15" FontWeight="Normal" FontStretch="Expanded" FontFamily="Verdana" FontStyle="Normal" VerticalAlignment="Top" HorizontalContentAlignment="Right" FlowDirection="LeftToRight" Padding="1" Margin="1,0,3,0" VerticalContentAlignment="Bottom" >
<MenuItem.Icon>
<Image Source="/WpfApplication4;component/Images/Computer.png" />
</MenuItem.Icon>
</MenuItem>
</Grid>
</Grid>
Try this
<MenuItem.Header>
<TextBlock Text="Header" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</MenuItem.Header>
Related
I want to make searchbox like when I search Items then listbox is show in this page. I have make listbox page is in another wpf window. Can you please help on this I am facing maki problem regarding this.
When I search listbox Items from MainWindow.Xaml and click button then of item show in main page. and Items on See software page.
Thankyou!
MainWindow.xaml
<Window Title="Welcome" Background="#FFD6D6D6" WindowStyle="None" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen" MouseDown="Window_MouseDown"
AllowsTransparency="True" Height="600" Width="1050">
<!--Make serchbar -->
<Grid Background="#2892b5" Grid.Column="3" Margin="10,0,0,0" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition />
</Grid.RowDefinitions>
<Viewbox HorizontalAlignment="Left" Margin="22,4,0,0" VerticalAlignment="Center" Width="65">
<Image Source="/Resources/search_32px.png" Height="40" Width="70" />
</Viewbox>
<Viewbox HorizontalAlignment="Center" Margin="70,4,0,0" VerticalAlignment="Center" >
<Label Content="Search for software" FontWeight="Bold" FontSize="20" Foreground="White" Grid.Row="0" Width="286"/>
</Viewbox>
<TextBox Background="White" Foreground="Black" x:Name="search" FontSize="20" Grid.Row="1" TextChanged="TextBox_TextChanged" Margin="37,0,36,38"/>
<Button Grid.Row="1" Height="37" Width="37" Background="Transparent" BorderBrush="Transparent" VerticalAlignment="Top" HorizontalAlignment="Right">
<Image Source="/View/icons8_right_50px_1.png"/>
</Button>
</Grid>
MainWindow.xaml.cs
private void SearchClick_Click(object sender, RoutedEventArgs e)
{
}
SeeSoftware.xaml
<Window Title="SeeSoftware" Height="700" Width="800" WindowStyle="None" MouseDown="Window_MouseDown">
<ListBox x:Name="Listbox" Foreground="White" FontSize="15" BorderBrush="Transparent" Background="Transparent">
<ListBoxItem Height="50">
<StackPanel Orientation="Horizontal" Margin="20,0,0,0" HorizontalAlignment="Left">
<Image Height="30" Width="30" Source="/Resources/vscode.jpeg"/>
<Label VerticalAlignment="Center" Foreground="White" FontSize="18" Margin="20,0,0,0" Content="Visual Studio code" />
<TextBlock Margin="18,0,0,0" FontSize="18" VerticalAlignment="Center" >
<Hyperlink Foreground="White" NavigateUri="https://az764295.vo.msecnd.net/stable/6261075646f055b99068d3688932416f2346dd3b/VSCodeUserSetup-x64-1.73.1.exe" RequestNavigate="Hyperlink_RequestNavigate">
Install
<Image Height="13" Source="/Resources/icons8_download_26px.png"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</ListBoxItem>
</ListBox>
I am trying to make an image stretch to fit the screen with preserverd aspect ratio. I thought this code would do the trick:
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenHeight}" Stretch="Uniform" StretchDirection="Both"/>
Regretably it seems like the image just fits to the width of the screen and crops it at the bottom.
The complete xaml code looks like this:
enter co<Window x:Class="ImageExplorer.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:ImageExplorer"
mc:Ignorable="d"
Title="MainWindow" WindowState="Maximized" Background="Black">
<StackPanel>
<Border BorderBrush="Black" BorderThickness="2">
<Grid Margin="0,0,0,0">
<Button Content="open" Click="OpenImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="1,1,1,1" />
<Button Content="Prev." Click="GetPreviousImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="120,1,1,1"/>
<Button Content="Next" Click="GetNextImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="180,1,1,1" />
<Label Content="Fil:" HorizontalAlignment="Right" VerticalAlignment="Center" Width="120" Height="30" Margin="1,1,300,1"/>
<TextBlock Name="StiViser" HorizontalAlignment="Right" VerticalAlignment="Center" Width="298" Margin="1,1,1,1" TextWrapping="Wrap" Text="TextBlock"/>
</Grid>
</Border>
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" Stretch="Uniform" StretchDirection="Both"/>
</StackPanel>
Use DockPanel instead
<DockPanel LastChildFill="True">
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="2">
<Grid Margin="0,0,0,0">
<Button Content="open" Click="OpenImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="1,1,1,1" />
<Button Content="Prev." Click="GetPreviousImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="120,1,1,1"/>
<Button Content="Next" Click="GetNextImage" HorizontalAlignment="Left" VerticalAlignment="Center" Width="58" Height="30" Margin="180,1,1,1" />
<Label Content="Fil:" HorizontalAlignment="Right" VerticalAlignment="Center" Width="120" Height="30" Margin="1,1,300,1"/>
<TextBlock Name="StiViser" HorizontalAlignment="Right" VerticalAlignment="Center" Width="298" Margin="1,1,1,1" TextWrapping="Wrap" Text="TextBlock"/>
</Grid>
</Border>
<Image Name="Viewer" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" Stretch="Fill" StretchDirection="Both"/>
</DockPanel>
I am trying to get my view to only tab between a pick username textbox and a massage textbox xaml. My first problem is the tab gets stuck on the enter username, my guess is it has a custom control for search suggestions that is next in line. Also it tabs through every button in the view and i don't want it to do that. I have tried to add a Tabindex to both textboxes and it has no effect. I left the Tabidex in both textboxs so you know which ones I am trying to tab between.
<UserControl x:Class="Clinical.Patient.Views.SendMessageDialogView"
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"
d:DataContext="{d:DesignInstance
Type=viewModels:SendMessageDialogViewModel}"
mc:Ignorable="d"
d:DesignWidth="320"
xmlns:properties="clr-namespace:Clinical.Patient.Properties"
xmlns:viewModels="clr-namespace:Clinical.Patient.ViewModels"
xmlns:patient="clr-namespace:Clinical.Patient"
xmlns:self="clr-namespace:System;assembly=mscorlib"
xmlns:views="clr-namespace:Clinical.Patient.Views"
d:DesignHeight="350"
xmlns:termAutoComplete="clr-
namespace:Clinical.Patient.Controls.TermAutoComplete"
xmlns:controls="clr-namespace:Clinical.Patient.Controls"
KeyboardNavigation.TabNavigation="Local">
<UserControl.Resources>
<viewModels:IsAtLeastGradeConverter x:Key="IsAtLeastGradeConverter"/>
<viewModels:IsAtLeastAutoCloseGradeConverter x:Key="IsAtLeastAutoCloseGradeConverter"/>
</UserControl.Resources>
<Border Padding="8"
MinWidth="320"
ClipToBounds="False">
<Border BorderThickness="1"
BorderBrush="{DynamicResource FocusBorderBrush}"
CornerRadius="2"
Background="{DynamicResource FocusBackgroundBrush}">
<Border.Effect>
<DropShadowEffect Color="{DynamicResource SubtleDivideBorderColor}"
Opacity="1"
ShadowDepth="0"
BlurRadius="10" />
</Border.Effect>
<StackPanel Orientation="Vertical"
Margin="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{x:Static properties:Strings.SharingReportIs}"
Foreground="{DynamicResource CommonTextBrush}"
FontSize="13"
FontWeight="Bold"/>
<Border Grid.Column="1"
Width="180"
Margin="5 5 20 5"
HorizontalAlignment="Left"
Background="{DynamicResource FocusBackgroundBrush}"
BorderBrush="{DynamicResource FocusBorderBrush}"
BorderThickness=".5"
CornerRadius="8,8,8,8">
<DockPanel HorizontalAlignment="Center">
<views:ExamTypeIconView DockPanel.Dock="Left"
Type="{Binding ExamType}"
Foreground="{DynamicResource CommonTextBrush}"
IconHeight="30"/>
<StackPanel DockPanel.Dock="Left"
Margin="3">
<TextBlock Text="{Binding Status}"
Foreground="{DynamicResource CommonTextBrush}"
FontSize="13"/>
<TextBlock Text="{Binding Accession}"
Foreground="{DynamicResource CommonTextBrush}"
FontSize="13"/>
</StackPanel>
</DockPanel>
</Border>
</Grid>
<DockPanel HorizontalAlignment="Left"
MinWidth="280"
Margin="0 5 0 0">
<Button
x:Name="To"
HorizontalAlignment="Right"
MinWidth="65"
Margin="0,4,4,4"
IsDefault="True"
Command="{Binding ToCommand}"
Content="to.." Width="65" />
<TextBox x:Name="SendTo"
Text="{Binding Recipient, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Style="{DynamicResource NavigationSearchTextBox}"
FontSize="{DynamicResource OneAndAQuarterFontSize}"
Padding="0 3 0 3"
VerticalAlignment="Center"
Width="225"
TabIndex="0"/>
<termAutoComplete:TermAutoComplete AutoCompleteSource="{Binding AutoCompleteSource}"
Padding="0 0 0 0"
TextBox="{Binding ElementName=SendTo}"/>
</DockPanel>
<Grid Margin="0 5 0 0">
<TextBlock Text="{x:Static properties:Strings.SharingMessage}"
Foreground="{DynamicResource CommonTextBrush}"
FontSize="13"
FontWeight="Bold" />
</Grid>
<TextBox x:Name="PeerReviewComments"
Margin="0 5 0 0"
MinLines="5"
AcceptsReturn="True"
TextWrapping="Wrap"
Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Width="295"
TabIndex="1"/>
<DockPanel
MinWidth="280"
Margin="0,5,-5,0"
>
<Button
x:Name="Save"
HorizontalAlignment="Right"enter code here
MinWidth="65"
Margin="0,4,4,4"
IsDefault="True"
Command="{Binding SendCommand}"
Content="Send" Width="65"
DockPanel.Dock="Right"
/>
<Button
x:Name="Cancle"
HorizontalAlignment="Right"
MinWidth="65"
Margin="0,4,4,4"
IsDefault="True"
Command="{Binding CancelCommand}"
Content="Cancel" Width="65"
DockPanel.Dock="Right"
/>
</DockPanel>
</StackPanel>
</Border>
</Border>
</UserControl>
I believe you need to replace "TabIndex" with "KeyboardNavigation.TabIndex".
If that doesn't work, you can also skip elements in the tab sequence by setting KeyboardNavigation.IsTabStop on the element in XAML.
KeyboardNavigation.IsTabStop="False"
Source
For controls where tab "gets stuck" add:
KeyboardNavigation.TabNavigation="Continue"
To avoid tab hitting a control add:
KeyboardNavigation.IsTabStop="False"
I am trying to make a WPF window with some comboboxs and menus.
After any comboxbox or the menu is opened or clicked , when I try to close/minimize/maximize using the icons built-in with the WPF window itself , it takes me two clicks , the first one is to close the menu/combox and the second click is to close/minimize/maximize.
I want to overcome this behavior , which means to close/minimize/maximize the WPF window by one single click regardless any open menus or comboboxes.
Any help please?
<Window x:Class="ConnectionTable.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:ConnectionTable"
mc:Ignorable="d"
Closing="Window_Closing"
Title="GUI Console" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Grid HorizontalAlignment="Stretch" Height="auto" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="auto">
<Button x:Name="b1" Content="Connect" HorizontalAlignment="Right" Margin="0,0,56.333,23.333" VerticalAlignment="Bottom" Width="140" Height="52" Click="Button_Click"/>
<Button x:Name="b2" Content="Filter" HorizontalAlignment="Right" Margin="0,0,240.333,23.333" VerticalAlignment="Bottom" Width="140" Height="52" Click="Filter_Click" IsEnabled="False" />
<Button x:Name="b3" Content="Mail" HorizontalAlignment="Right" Margin="0,0,400.333,23.333" VerticalAlignment="Bottom" Width="140" Height="52" Click="SendMail" IsEnabled="False"/>
<DataGrid x:Name="dg" IsReadOnly="True" Margin="50,47,56.333,114.333" Background="#FFC9DEF5" />
<ComboBox x:Name="cbox" HorizontalAlignment="Left" Margin="39,550,0,22.333" Width="150" Height="30" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
</ComboBox>
<ComboBox x:Name="cbox2" HorizontalAlignment="Left" Margin="200,550,0,22.333" Width="150" Height="30">
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="70" CanContentScroll="True" Width="150" >
<StackPanel x:Name="spanel2" CanVerticallyScroll="True"/>
</ScrollViewer>
</ComboBox>
<Menu HorizontalAlignment="Stretch" VerticalAlignment="Top">
<MenuItem Header="_File">
<MenuItem Command="Save" HorizontalAlignment="Left" Width="150"/>
<Separator HorizontalAlignment="Left" Width="150"/>
<MenuItem Command="Close" HorizontalAlignment="Left" Width="150"/>
</MenuItem>
<MenuItem Header="_Edit">
<MenuItem Command="Cut" />
<Separator HorizontalAlignment="Left" Width="140"/>
<MenuItem Command="Copy" />
<Separator HorizontalAlignment="Left" Width="140"/>
<MenuItem Command="Paste" />
</MenuItem>
</Menu>
</Grid>
I'm working on wpf application , and i want to use the shape of an exsiting image . i made the background of the windows transparent and i added the image , and some buttons but when i excute the application nothing apears .
here is the code
<Controls:MetroWindow x:Class="Selen.Wpf.DemoApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:System="clr-namespace:System;assembly=mscorlib" Title="A propos "
Height="300" Width="450" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" TitleForeground="#999988" Background="Transparent"
WindowStyle="None" ShowMaxRestoreButton="False" SizeToContent="WidthAndHeight" AllowsTransparency="True" >
<Grid >
<Border CornerRadius="20,20,20,20" Background="Cornsilk"/>
<Image Height="300" Width="450" Name="test" Source="test1.png" Visibility="Visible"
Stretch="Fill" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
<Button x:Name="projet" Width="40" Background="Transparent" Visibility="Visible" Margin="64,0,346,260" Click="projet_Click" Cursor="Hand" Height="40" VerticalAlignment="Bottom" >
<Image Width="40" Height="40" Source="pro.png"></Image>
</Button>
<Button x:Name="equipe" Background="Transparent" Width="40" Visibility="Visible" Margin="105,0,305,260" Click="equipe_Click" Cursor="Hand" >
<Image Source="equ.png" Width="40" Height="40" ></Image>
</Button>
<Button x:Name="outils" Width="40" Background="Transparent" Margin="146,0,264,260" Visibility="Visible" Click="outils_Click" Cursor="Hand" Height="40" VerticalAlignment="Bottom" >
<Image Source="outi.png" Width="40" Height="40" ></Image>
</Button>
<TextBlock x:Name="titr" Height="30" Width="350" Margin="10,67,90,203" FontSize="16" TextDecorations="Underline" Foreground="White" Text="Modélisation des surfaces topographique :" />
<TextBlock x:Name="txt" Height="180" Width="300" Margin="10,102,140,18" Text="le text sera met ici" Foreground="White" />
<Image x:Name="image" Height="100" Width="100" Margin="328,130,22,70" />
</Grid>
how can i solve that problem ?
ps : i did already add the image to the project .
You have to use Source="/ApplicationName;component/Images/imagename.png" .
Under the brush catagory in your pages properties Select the background (Has an image icon)
Then set the image source to your picture. it should be in the drop down list
Change the build action of the images to 'Resource'. Also your images path seems to be wrong.
Your Project Setup should like this,
and XAML is
<Grid >
<Border CornerRadius="20,20,20,20" Background="Cornsilk"/>
<Image Height="300" Width="450" Name="test" Source="Images/test1.png" Visibility="Visible"
Stretch="Fill" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
<Button x:Name="projet" Width="40" Background="Transparent" Visibility="Visible" Margin="64,0,346,260" Click="projet_Click" Cursor="Hand" Height="40" VerticalAlignment="Bottom" >
<Image Width="40" Height="40" Source="Images/equ.png"></Image>
</Button>
<Button x:Name="equipe" Background="Transparent" Width="40" Visibility="Visible" Margin="105,0,305,260" Click="equipe_Click" Cursor="Hand" >
<Image Source="Images/outi.png" Width="40" Height="40" ></Image>
</Button>
<Button x:Name="outils" Width="40" Background="Transparent" Margin="146,0,264,260" Visibility="Visible" Click="outils_Click" Cursor="Hand" Height="40" VerticalAlignment="Bottom" >
<Image Source="Images/pro.png" Width="40" Height="40" ></Image>
</Button>
<TextBlock x:Name="titr" Height="30" Width="350" Margin="10,67,90,203" FontSize="16" TextDecorations="Underline" Foreground="White" Text="Modélisation des surfaces topographique :" />
<TextBlock x:Name="txt" Height="180" Width="300" Margin="10,102,140,18" Text="le text sera met ici" Foreground="White" />
<Image x:Name="image" Height="100" Width="100" Margin="328,130,22,70" />
</Grid>
</Grid>