I am new to WPF. I want to create a dropdown menu similar to this image. I am not getting from which control should I start the implementation of ControlTemplate.
I guess It is a Hyperlink with a ContextMenu.
WPF Popup control is exactly what you are looking for:
<Popup Name="myPopup" IsOpen="True">
<Label Name="myLabel" Content="Language: English"
Background="Black" Foreground="White"/>
<...other controls you like.../>
</Popup>
Related
How to create in WPF C# App a customized pop up window (Message Box) like windows 8/ windows store apps popups, is it feasible to create it? I need to have the design as the attached image
I'm using Devexpress for WPF as third parties controls.
thanks
Yes, put everything in a grid followed by another grid containing the message box. The rest is up to you to show and hide the message box and style it. The grid with the background makes everything un-interactable.
<Grid>
<!--Everything-->
<Grid Background="#6666">
<Border Background="White" VerticalAlignment="Center" Padding="10">
<StackPanel HorizontalAlignment="Center" MinWidth="300">
<TextBlock Text="My Title"/>
<WrapPanel HorizontalAlignment="Right">
<Button Content="Ok"/>
<Button Content="Cancel"/>
</WrapPanel>
</StackPanel>
</Border>
</Grid>
</Grid>
With DevExpress you are probably looking at either:
WinUIMessageBox
WinUIDialogWindow
Both can be found at this link.
I think you may want to use the FlyoutControl for this. DevExpress has a nice example of using it in a modal form in their How To: Create a Modal Message Box Flyout documentation.
first post here so if I do anything wrong please slap me.
I'm currently trying to learn UWP code and I want to try to create a bottom naivation bar. I'm trying to work with stackpanels to do so
The idea is that when a stackpanel is clicked / tapped it should load a new page into viewport, however I can't figure out the correct code to do so. Here's an short version of my stackpanel:
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<StackPanel Name="FirstButton" Tapped="FirstButton_Tapped">
<TextBlock x:Name="Icon1" />
<TextBlock x:Name="Text1" />
</StackPanel>
<StackPanel Name="SecondButton" Tapped="SecondButton_Tapped">
<TextBlock x:Name="Icon2" />
<TextBlock x:Name="Text2" />
</StackPanel>
<StackPanel Name="ThirdButton" Tapped="ThirdButton_Tapped">
<TextBlock x:Name="Icon3" />
<TextBlock x:Name="Text3" />
</StackPanel>
I chose stackpanel because that was the best way for me to have a bottom and horizontal aligned bar with an icon on top and text displaying under it.
(if you got a better idea feel free to post it)
Now the question is how i should write my C# code so that the Tapped event will load a second page into the viewport.
(further, the style I'm aiming for is something similar to what deezer uses, example is here: http://imgur.com/WNNi96v
Thank you in advance!
As #Pedro G. Dias says far better to use Button control as it has many more benefits (Visual States) that you associate with user clicking/ Tapping a Button rather than using the Tap event of StackPanel
You can customise a Button easily by utilising the ContentTemplate
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<Button x:Name="FirstButton" Click="FirstButton_Click">
<Button.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="Icon1" />
<TextBlock x:Name="Text1" />
</StackPanel>
</DataTemplate>
</Button.ContentTemplate>
</Button>
<!--More buttons here-->
</StackPanel>
Simply create buttons and place them inside each stackpanel. The button.Content property of the Button control will let you put the two textblocks inside it.
I'm using Fluent Ribbon and I use ApplicationMenu for Ribbon's Menu. I want to create an ApplicationMenu look like this:
Right now I'm using a StackPanel to create the item which inside the red circle in the image above.
So I wonder if there a better way to create that? Is Fluent Ribbon support a control like that? If yes, what control is that and how can I use it?
To create a header for some content, you can try HeaderedContentControl. Eg;
<HeaderedContentControl Header="_JPEG Picture" Canvas.Left="220" Canvas.Top="116">
<DockPanel Margin="-50 0 0 0">
<Image Source="img/penguins.jpg" Width="50" Height="50"/>
<TextBlock Text="save a picture"/>
</DockPanel>
</HeaderedContentControl>
For keyboard mnemonics, you can provide template for Header like :
<HeaderedContentControl.HeaderTemplate>
<DataTemplate>
<Label Content="{Binding Header, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=HeaderedContentControl}}"/>
</DataTemplate>
</HeaderedContentControl.HeaderTemplate>
I am trying to create a popup that opens similar to the window preview option in Windows 8 taskbar. Basically, when I click or hover on a button, it opens a popup with basic information just above the button. Here is an example.
Right now, I am able to open the popup at either the extreme left or extreme right side of the page, using the code below.
<Frame x:Name="PopUpFrame" HorizontalAlignment="Left" Visibility="Hidden" Height="400" Margin="10,10,0,0" Grid.Row="1" VerticalAlignment="Bottom" Width="400" Source="/BasicApp;component/StandingOrderPopUp.xaml" NavigationUIVisibility="Hidden"/>
I have 3 different buttons in the button bar, so I cannot set the fixed margin. I am trying to set the same in code but I am unable to get the absolute position and convert it to margin property. I am not sure, if there is a better solution either.
Edit:
Tried using popup but it doesn't open on button click.
<Popup x:Name="PopUpFrame" Placement="Top" PlacementTarget="{Binding ElementName=StandingOrderButton}" Width="400" Height="400">
<DockPanel Background="#770081a7">
<Canvas DockPanel.Dock="Bottom" x:Name="PopupButtonBar" Height="50" VerticalAlignment="Bottom">
<Button Height="30" Width="125" HorizontalAlignment="Right" VerticalAlignment="Center" Canvas.Top="10" Content="CLOSE" Foreground="White" Background="#ff0081a7" BorderBrush="White" FontFamily="Trebuchet MS" Canvas.Left="10" />
</Canvas>
<Label Margin="5,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DockPanel.Dock="Top" Content="STANDING ORDERS" Foreground="#ffffffff"></Label>
<Grid DockPanel.Dock="Top">
<Border BorderThickness="2" BorderBrush="#FFff7a00"></Border>
<RichTextBox Margin="2" Foreground="#FF0081a7" FontFamily="Trebuchet MS" IsEnabled="False"/>
</Grid>
</DockPanel>
</Popup>
And here is the event handler.
Private Sub StandingOrder_Click(sender As Object, e As RoutedEventArgs)
PopUpFrame.Visibility = Windows.Visibility.Visible
End Sub
Edit:
Never mind. I am an idiot. Instead of setting IsOpen property, I set the visibility. :(
It works perfectly, although, I had to copy the whole design from the separate page to this one. Still better than nothing. Only problem now is if I click on something else, I will have to write code to make sure popup is closed.
You can use a Popup control, coupled with it's Placement property to display your popup based on the current location of your buttons.
<Popup Placement="Top" PlacementTarget="{Binding ElementName=yourButton}" ... />
Inside your Popup, you can place your UserControl or any content element which will act as the popup's content.
See here for further information on popup placements, and here for a tutorial on WPF Popup controls.
Think about using ContextMenu, and set it's content you whatever you want. Thats is the solution for you.
This is how i defined one of my popups:
<Popup x:Name="btnPowerPopup" Placement="Mouse" StaysOpen="False">
....
</Popup>
you can user from the code behind on a button click or something :
btnPowerPopup.IsOpen = true;
and when the job is done:
btnPowerPopup.IsOpen = false;
But StaysOpen="False" let's you close the PopUp when clicking somewhere else.
I am using a wpf popup control.
<Popup x:Name="tabHolder" IsOpen="False"
PopupAnimation="Slide" Placement="Bottom"
PlacementTarget="{Binding ElementName=mainWidgetWindow}">
<Grid Height="105" Width="315" />
</Popup>
Here I have set popup animation property to slide. But when it opens, it doesn't animate. Do I have to add any other configuration for popup to open with animation option slide?
I am using .net framework version 3.5.
From MSDN
A Popup can only animate when the AllowsTransparency property is set to true. This requires the application that creates the Popup control to run with full trust.
If the PlacementTarget is animated, the Popup will not be animated.
XAML should look like
<DockPanel Width="500" Background="Aqua">
<Popup Placement="Center" PlacementRectangle="0,0,30,50"
IsOpen ="True" AllowsTransparency="True"
PopupAnimation="Fade">
<TextBlock Background="Purple">Popup Text</TextBlock>
</Popup>
</DockPanel>
And you can read more here.
Popup will animate if you have set AllowsTransparency true.
like -
AllowsTransparency="True".