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>
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>
A large black area appears on the right side of the window when I run the program, and I can't figure out why. It's not there in the preview on the XAML file page in Visual Studio 2017, and I ran it once on a Windows 7 computer, and the black area wasn't there (I'm primarily on Windows 10). The problem could possibly be in another file, but I cannot find it.
<Window x:Class="Project.Widget"
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:Project"
mc:Ignorable="d"
Title="Menu"
WindowStartupLocation="Manual"
ResizeMode="NoResize"
Width="109"
SizeToContent="WidthAndHeight"
WindowState="Minimized"
Background="#2D3A48"
Topmost="False"
Loaded="Window_Loaded"
Closing="Window_Closing" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="77"/>
<RowDefinition Height="28"/>
<RowDefinition Height="90"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Image x:Name="Icon"
Source="./Resources/Icon.png"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Height="77"
Width="109" />
<Label x:Name="labelUsername"
Grid.Row="1"
Content=""
FontSize="14"
Foreground="White"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" />
<Label x:Name="labelScore"
Grid.Row="2"
Content="0%, 0 of 0"
Foreground="White"
FontSize="14"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,0,0,0" />
<Image x:Name="AvgScoreDot"
Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Height="50"
Source=".\Resources\yellow_dot.png"
Margin="0,32,0,0"/>
<Label x:Name="labelAvgScore"
Grid.Row="2"
Content="0.0"
Foreground="White"
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,35,0,0"
FontWeight="Bold" />
<Button x:Name="MailBtn"
Grid.Row="3"
Height="60"
Width="109"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="#FF2D3A48"
Click="Mail_Click" >
<Button.Background>
<ImageBrush
ImageSource="/Resources/mail.png"
Stretch="None" />
</Button.Background>
</Button>
<Button x:Name="MailBadgeBtn"
Grid.Row="3"
Content="0"
Foreground="White"
FontSize="11"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Height="20"
Width="20"
Margin="0,30,24,10"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Click="MailBadgeBtn_Click" BorderThickness="0">
<Button.Background>
<ImageBrush
ImageSource=".\Resources\red_dot.png" />
</Button.Background>
</Button>
<TextBlock x:Name="labelConnection"
Grid.Row="0"
Text=" No Connection or blocked by Firewall"
Foreground="Red"
Background="White"
TextWrapping="Wrap"
TextAlignment="Center"
VerticalAlignment="Center"
Height="77"
Width="109"
HorizontalAlignment="Center" />
</Grid>
Here's an image of what I get when I run it:
Here's what I get when I remove SizeToContent="WidthAndHeight" and add a height of 300 (I also had to remove your event handlers since I don't have that code, and add garbage images to the Resources folder since I don't have the original images):
Is that more like what you were looking for? You can also choose to explicitly set SizeToContent to "Manual".
I was wondering how to set a camera resolution in 16;9 aspect ratio in windows universal app, I have tried different codes but none of them are working also I am losing a bit of frame rate when I used some of the codes below i don't know how to set a camera resolution to 16;9 that is a problem is there any function inside VideoeEcodingProporties that will help me to accomplish this.
XAML UWP CODE;
<Page
x:Class="whatchado_recorder.Video.Capture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:whatchado_recorder"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
SizeChanged="Page_SizeChanged">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel x:Name="CaptureStack" Visibility="Collapsed" Margin="0,12,0,0" HorizontalAlignment="Stretch" MaxWidth="720">
<ProgressBar x:Name="RecordProgress" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="6" Minimum="0" Maximum="90"/>
<TextBlock x:Name="CameraErrorTextBlock" x:Uid="NoCameraFound" Margin="0,120,0,24" HorizontalAlignment="Center" Text="No camera found :(" VerticalAlignment="Center" FontSize="24" Visibility="Collapsed"/>
<Grid x:Name="CaptureGrid" Margin="0,12,0,0">
<CaptureElement x:Name="CaptureElement" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="360" Tapped="captureElement_Tapped"/>
<Border Background="Black" Padding="6" Opacity="0.5" HorizontalAlignment="Center" VerticalAlignment="Top">
<TextBlock Foreground="White" FontSize="12">
<Run x:Uid="MaxTime" Text="Max. Time: "/>
<Run Text="{Binding Path=Args.SelectedQuestionOnRecordStart.MaxVideoLength, Converter={StaticResource DoubleToStringConverter}}"/>
</TextBlock>
</Border>
<local:MouseOver x:Name="BackgroundCircle" HorizontalAlignment="Center" VerticalAlignment="Center">
<local:MouseOver.NormalState>
<Ellipse Fill="Black" Opacity="0.25" HorizontalAlignment="Center" VerticalAlignment="Center" Width="192" Height="192" Tapped="captureElement_Tapped"/>
</local:MouseOver.NormalState>
<local:MouseOver.MouseOverState>
<Ellipse Fill="Black" Opacity="0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Width="192" Height="192" Tapped="captureElement_Tapped"/>
</local:MouseOver.MouseOverState>
</local:MouseOver>
<Ellipse x:Name="RecordCircle" Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="36" Height="36" Tapped="captureElement_Tapped"/>
<local:MouseOver x:Name="BackgroundStopCircle" Visibility="Collapsed" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,24">
<local:MouseOver.NormalState>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="64" Height="64">
<Ellipse Fill="Black" Opacity="0.25" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="captureElement_Tapped"/>
<Rectangle Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" Tapped="captureElement_Tapped"/>
</Grid>
</local:MouseOver.NormalState>
<local:MouseOver.MouseOverState>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="64" Height="64">
<Ellipse Fill="Black" Opacity="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="captureElement_Tapped"/>
<Rectangle Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" Tapped="captureElement_Tapped"/>
</Grid>
</local:MouseOver.MouseOverState>
</local:MouseOver>
<TextBlock x:Name="CountdownText" Visibility="Collapsed" Foreground="White" FontSize="72" Margin="0, -48, 0, 0" Text="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock x:Name="ExplanationText" x:Uid="LookIntoCamera" Visibility="Collapsed" Foreground="White" FontSize="12" Margin="0, 48, 0, 0" Text="Look into the camera" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Button x:Name="CancelButton" x:Uid="Cancel" Content="Cancel" Style="{StaticResource NormalButtonStyle}" Margin="0,12,0,0" Padding="24,0,24,0" HorizontalAlignment="Right" Click="cancelButton_Click"/>
</StackPanel>
</Grid>
</Page>
UWP CS.CODE;
var maxPreviewResolution = mc.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Height > (i2 as VideoEncodingProperties).Height ? i1 : i2);
await mc.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, maxPreviewResolution);
`
You could take a look at the camera resolution sample
See:
IEnumerable<StreamResolution> allPreviewProperties = _previewer.MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => new StreamResolution(x));
Once you have the mediaStream properties you can look for where
width/16 == height/9
to find all resolutions that match your ratio
How could we arrange the controls on a WPF window so that it would automatically align the controls while switching between view modes occur ie between landscape and portrait mode.
<Window x:Class="Custom_Track_Reports.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginWindow" >
<Viewbox Stretch="Fill">
<Grid Background="#FF58B0DF" Height="401">
<Rectangle Fill="#FFF0F3F4" Height="173" Margin="45,197,58,0" Stroke="Black" VerticalAlignment="Top" AllowDrop="True" />
<Image Height="125" Margin="340,10,330,0" VerticalAlignment="Top" Source="Images/logo_lrg.png"/>
<Label Content="Custom Track Reports" HorizontalAlignment="Left" Margin="287,147,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.607,1.112" Width="268" Height="47" FontFamily="Arial" FontSize="26" Foreground="White"/>
<TextBox Margin="128,0,0,110" TextWrapping="Wrap" VerticalAlignment="Bottom" Height="25" BorderThickness="1" FontFamily="Arial" FontSize="21" Text="" Name="userTextBox" FontStretch="Expanded" Opacity="1" HorizontalAlignment="Left" Width="546" AcceptsReturn="False" KeyDown="userTextBox_KeyDown" />
<Button x:Name="enterButton" Content="Enter" HorizontalAlignment="Right" Margin="0,311,166,0" VerticalAlignment="Top" Width="110" Height="26" FontSize="14" Style="{DynamicResource button}" Click="enterButton_Click"/>
<Label Content="User ID" FontSize="20" FontWeight="Bold" Height="40" HorizontalAlignment="Left" Margin="122,215,0,0" Name="label1" VerticalAlignment="Top" Width="105" />
</Grid>
</Viewbox>