WPF Popup like Windows Form - c#

I would like to create a popup in wpf that behaves as windows form. I have manage to close the popup using [x] when it displays. I am stuck on how I can add functional minimize and maximize buttons feature.
here is how i achieved the first step: close button:
How to place close [x] in WPF popup
<Popup Name="myPopup" IsOpen="True">
<StackPanel>
<Label Background="AliceBlue" Foreground="Blue" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" MouseDown="mouse_DownHandled">
x
</Label>
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
</StackPanel>
</Popup>
the mouse_DownHandled event closes the popup by setting isOpen=false
Any ideas?Thanks.

I see what you want. I think what you want is not a Popup Control but actually a WPF Window with a special style set in it.
Use the WindowStyle property to achieve this.
Use
<Window Name="myPopup" WindowStyle="SingleBorderWindow">
<StackPanel>
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
</StackPanel>
</Window>
If you want to show this from the code, you can create create an instance of the view and call
window.Show()
Your window should look like this

Related

Wpf send layout object not by button or textbox

I've got a little bit problem with sending my layout object. I'm trying to create an WPF app in style like a chrome with draggable cards. To do this, I'm using OpenControls.Wpf library + Prism + MahApps.Metro
Layout declarated in main xaml view
<dockManager:LayoutManager x:Name="_layoutManager" Grid.Row="1" Grid.Column="0"
DocumentsSource="{Binding Documents}" ToolsSource="{Binding Tools}"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" UseLayoutRounding="False"
Margin="0,-4,0,0">
<dockManager:LayoutManager.Theme>
<themes:ModernTheme/>
</dockManager:LayoutManager.Theme>
<dockManager:LayoutManager.DocumentTemplates>
<DataTemplate DataType="{x:Type usViewModel:UsersModule_ViewModel}" >
<usViews:UsersModule_View x:Name="UsersModuleModule" Margin="4"/>
</DataTemplate>
</dockManager:LayoutManager.DocumentTemplates>
</dockManager:LayoutManager>
Buttons to open projects in card in the same xaml file
<StackPanel>
<Button x:Name="myButton" Style="{StaticResource ButtonMore}" Content="Users"
Command="{Binding LoadModule1Command}"
CommandParameter="{Binding ElementName=_layoutManager}"
HorizontalAlignment="Left" Margin="24,80,24,0" VerticalAlignment="Top" Width="208" Height="40"/>
</StackPanel>
By the DelegateCommand { get; private set; } in my module, through the button CommandParameter is sending an layoutManager object. I need to get that object, but without click any button or textbox.
So my main question:
Is it possible, to send an object without any buttons or is it possible to programmatically call of the click event in WPF.
I've search something about that problem, but did not find any solution.

How to catch activated command from child component to parent component in WPF?

I've got a MainWindow that contains a main menu. The menu is a UserControl, consisting of a StackPanel with Buttons inside.
The simplified XAML code is as follows:
<Window>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<local:MainMenu Grid.Column="0"></local:MainMenu> <!-- the navigation menu -->
<ContentControl Grid.Column="1" Content="{Binding CurrentView}" />
</Grid>
</Window>
<!-- The navigation menu UserControl -->
<UserControl Class="MyApp.MainMenu" ...etc... >
<StackPanel>
<Button Style="{StaticResource menuButton}">To do</Button>
<Button Style="{StaticResource menuButton}">Notes</Button>
<Button Style="{StaticResource menuButton}">Settings</Button>
<Button Style="{StaticResource menuButton}">News</Button>
<Button Style="{StaticResource menuButton}">Calendar</Button>
<Button Style="{StaticResource menuButton}">...</Button>
<Button Style="{StaticResource menuButton}">...</Button>
<Button Style="{StaticResource menuButton}">...</Button>
</StackPanel>
</UserControl>
Now of course, when a Button in the menu UserControl is clicked, I want to notify the MainWindow that the user wants to navigate. The MainWindow has to change its CurrentView property. To show the corresponding view.
The problem I have is that I can't get any communication between components. It seems very hard to achieve this in WPF. There are tutorials on the internet, but they are not explaining well enough how to do it the right way.
I think it's a bad idea to just add Click event handlers to each button of the MainMenu. I would like to solve this using commands, and use a command parameter to determine what Button was clicked if that's good practise.
In the most ideal situation, could it be made that the menu just 'emits' something like an event, and that the window catches this? This way the child control (the menu UserControl) wouldn't have to be aware of its parent.
Can someone help me?
There are many ways you can do it. If you are using MVVM, you can just do command binding, if you have lets say ExitApp command in your MainWindow viewmodel,then you can do like this:
<vw:ImgButton Name="Exit" ClickCommand="{Binding DataContext.ExitApp, RelativeSource={RelativeSource AncestorType={x:Type Window}},Mode=OneWay}"/>
Optionally you can provide info in command parameter and do switching inside ExitApp command as well.
Made a mistake and review my answer. ContextMenu are not in the same "context" and binding are not working easily - I use a Forward command concept so menutiem command are forwarded to the MainViewModel - tell me if you need more, see in my project CBR and search for ForwardCommand

Add custom button to Form ControlBox

I want to know how to add additional button to Form ControlBox that is present at image below:
I know in this forum are few similar questions but no single one answered my question. I checked few links and its not that what i expected because its not working at every operating system. I checked those links:
http://www.codeproject.com/Articles/11510/Add-Transparent-Menus-and-XP-Titlebar-Buttons-to-y
http://www.codeproject.com/Articles/10171/Adding-a-Minimize-to-tray-button-to-a-Form-s-capti
Other idea is to change default click event and icon for MaximizeBox because i don't need this one in my app.
Scratch this - just realized it's a Winforms issue.
Kinda lame suggestion, but in WPF I'd do:
Drop the title
<Window> ... WindowStyle="None" ... /<Window>
Then roll my own:
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right">
<Button HorizontalAlignment="Right" Width="25" Content="Yo!"/>
<Button HorizontalAlignment="Right" Width="20" Content="-"/>
<Button HorizontalAlignment="Right" Width="20" Content="■"/>
<Button HorizontalAlignment="Right" Width="20" Content="X"/>
</StackPanel>
Caveats:
You will have to do a mouse capture to move the window, not difficult but not trivial either. Also change the style of the buttons to look like the regular icons etc
Not ideal I know, but in a pinch ...

how to avoid creating multiple popup when defining in xaml?

I want to show a popup in a page on a event. I have added a popup in a page's definition. It works fine for the 1st time. But since Popup is not a part of visual-tree, the popup gets created again when visiting the page next time. how can I avoid this? the only option I know is to write a static popup in code-behind. But is there any way I can do this in xaml? (or may be in VM)
this is my code in XAML.
<Popup Grid.Row="2" x:Name="popup" IsOpen="{Binding VenueListOpen}">
<ScrollViewer Height="600" Margin="0,0,0,20" Background="#55000000">
<StackPanel Width="{Binding DeviceWidth}">
<ItemsControl ItemsSource="{Binding EventsList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20,0" Background="{Binding BindsDirectlyToSource=True, Converter={StaticResource EventRowBackgroundConverter}}">
<TextBlock Margin="20,5" FontSize="30" Text="Metlife stadium" TextWrapping="Wrap"/>
<TextBlock Margin="20,5" Foreground="SkyBlue" Text="www.metlifestadium.com" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Popup>
How about setting its Visible property to false or true when you enter the page?
I have found a solution to this. May be there are better solution but this works for me:
in code behind, detach the binding by setting it to null. So whenever you move away the current popup will become orphan, and when u visit the page again, navigation will create new page as well as new popup up. but this time only new popup will appear, because the older popup is not in bound with datacontext so binding for IsOpen will not affect any older instance of that popup.

Listpicker with button in full mode in WP7

I put one button in listpicker full mode template. I want when this button is pressed. It Just invoke my defined event. Not act as normal tap on listpicker And closes the full mode of listpicker.
Please see screenshot below.
To include the button in the listPicker full mode, you have to define the data template as such. Go through the listPicker given here
<DataTemplate x:Name="PickerFullModeItemTemplate">
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<Button Click="event">
<Button.Content>
<StackPanel>
<Image Source="myImg.png"/>
<TextBlock Text="test"/>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</DataTemplate>
For the behavior you require. Try and test by handling event function on click event in the button. I guess it should work. If not then you have to use popUp instead of listPicker. Or you would have to define your own UserControl in the worst case.

Categories