wpf,xaml,clickable,expander , WPF expander not expanded above buttons make buttons unclickable

WPF expander not expanded above buttons make buttons unclickable


Tag: wpf,xaml,clickable,expander

In a WPF form, I have an expander that expands above other controls, such as buttons :

<Expander Grid.Row="0" Panel.ZIndex="99" Name="searchMenuExpander" Header="Search menu" FontWeight="Bold" HorizontalAlignment="Stretch" Margin="10,10,0,0" MinWidth="510" MinHeight="200" VerticalAlignment="Top" Foreground="MidnightBlue" Cursor="Arrow">
    <Grid Background="White">
        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        <TextBlock Text="Name" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20,10,0,0" Width="65" Height="20" Cursor="Arrow" />
        <TextBox Name="nameSearchTextBox"  HorizontalAlignment="Left" VerticalAlignment="Top" Margin="115,10,0,0" Width="100" Height="20"/>
<Button Content="Button" Height="34" Width="85"/>

My problem is that my controls that are behind the expander are not clickable anymore, even when the expander is not expanded. What is happening? How could I get rid of this bug?


I found a way of doing it, with code behind. I put my Expander in a Canvas and I added to my Expander two events:

Expanded="searchMenuExpander_Expanded" and Collapsed="searchMenuExpander_Collapsed" which are defined as:

    private void searchMenuExpander_Expanded(object sender, RoutedEventArgs e)
        Canvas.SetZIndex(searchMenuCanvas, 99);

    private void searchMenuExpander_Collapsed(object sender, RoutedEventArgs e)
        Canvas.SetZIndex(searchMenuCanvas, 0);


WPF Navigation using MVVM

I'm trying to follow the answer provided in this post, but I must be missing something trivial. I've defined my DataTemplates as App.xaml as follows: <Application.Resources> <DataTemplate DataType="{x:Type vm:BlowerViewModel}"> <v:BlowerView /> </DataTemplate> <DataTemplate DataType="{x:Type vm:HomeViewModel}"> <v:HomeView /> </DataTemplate> </Application.Resources> Then, in my MainWindow.xaml I've defined the following code: <Window x:Class="App.MainWindow"...

WPF add new Slider style cause XamlParseException

i found this slider style that i want to add. i added all the 3 styles inside my Window.Resources and also put in the first style the 2 templates: <Style TargetType="{x:Type Slider}"> <Setter Property="FocusVisualStyle" Value="{StaticResource MyFocusVisualStyte}" /> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type...

ItemsSource bind to collection stays empty

I have a class YouTubeVideo which contains some variables, which I would like to show on the UI. Therefore I created a custom control which shows all the data of the class. There are more than one instances of the class, so I would like to use an ItemsControl to...

WPF Listbox Collection custom sort

I have a listbox DropPrice MyPrice Price1 Price2 I want to sort it like this Price1 Price2 DropPrice MyPrice I mean, if there's an item that starts with the sequence "price", it gets priority, else the smallest string should get the priority. My source code: var lcv = (ListCollectionView)(CollectionViewSource.GetDefaultView(_itemsSource)); var...

In WPF how can I control whether another button clicked

I want to determine another button is clicked in wpf. I wrote same code as below, when I clicked that button the animation works after that when I clicked same button the animation work like as else block. But I want to control if another button is clicked and than...

Images aren't displayed in WPF ListBox

I'm trying to display images in a ListView. The images are being loaded through Entity Framework from a SQL Server database. Somehow the images don't get displayed in the ListView and I can't figure out why. I've created a test Visual Studio project. The images are stored in an ObservableCollection<ImageViewModel>:...

Open popup at the location of the button clicked

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...

Enable drag/drop and reordering after long click on GridView control (XAML)

I'm using the Items Page template from the Windows 8.1 Windows Store Apps templates in XAML. The page features a large GridView control with multiple item elements. I would like to enable the dragging and reordering of items, but only after a user long clicks one of the items (similar...

Microsoft Band and WPF

I have downloaded the sample code for Band SDK for Windows. Then I added a new WPF project and grabbed the latest SDK through Nuget (Version 1.3.10518.1). Now under packages\Microsoft.Band.1.3.10518\lib, the following folders are contained: netcore451 portable-net45+win+wpa81 portable-win81+wpa81 wpa81 Now as I need .NET 4.5 support I have referenced the...

CefSharp.Wpf WebView cannot accept input and the link clicked no response

I used CefSharp.Wpf in my application. version: 1.25.7. I hosted the webpage via CefSharp WebView. I can host my webpage in it. But the TextBox in the WebView cannot accept the input, and the hyperlink cannot response. Here is my code. I created a Wpf Usercontrol named WebPageOemViewer. Xaml: <UserControl...

WPF expander not expanded above buttons make buttons unclickable

In a WPF form, I have an expander that expands above other controls, such as buttons : <Expander Grid.Row="0" Panel.ZIndex="99" Name="searchMenuExpander" Header="Search menu" FontWeight="Bold" HorizontalAlignment="Stretch" Margin="10,10,0,0" MinWidth="510" MinHeight="200" VerticalAlignment="Top" Foreground="MidnightBlue" Cursor="Arrow"> <Grid Background="White"> <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> <TextBlock Text="Name" HorizontalAlignment="Left" VerticalAlignment="Top"...

Change the Location of DefaultPage in Universal App

How can I change the location of the default MainPage.xaml in an Universal Windows App? I want to have in the Windows and WindowsPhone Project a subfolder named "View" where I save the MainPage.xaml file like this example.  - Windows Project  -- View  --- MainPage.xaml  - WindowsPhone Project  -- View...

orderby () containing numbers and letters

I want to order an array containing numbers and letters in an ascending order the values are stored as a string in a DB. This is the list I have 4B 1A 1 1B 2 4C 4 and want them to order like this where numbers are ascending followed by...

How to print something in WPF without using controls? [closed]

I'm newbie in WPF and I'm trying to print student's exam papers using WPF and I'm creating exam papers using System.Drawing.Graphics and now I want to print them. But it seems every printable thing in WPF is somehow a control. I have two problems: I don't know how can I...

Why BindingFlags are called so?

Coming from WPF background,just wondering, why BindingFlags in Reflection are called so? What is so "binding" about it?

Add stack panel when check box is checked

I want to add stack panel dynamically when check box is checked and if check box is unchecked then i want to remove that stack panel. I tried following code. when i run the program and check the check box nothing is happening. private void bCheckbox_Checked(object sender, RoutedEventArgs e) {...

WPF: static INotifyPropertyChanged event

This is my model: class Person : INotifyPropertyChanged { public static int Counter; public string _firstName; public string _lastName; public event PropertyChangedEventHandler PropertyChanged; public string FirstName { get {return _firstname; } set { _fileName = value; NotifyPropertyChange("FirstName"); } } public AddPerson(Person person) { Counter++; } } I have this NotifyPropertyChange...

Changing color of positionmarker/caret

What is the name of the element of a text box control which I need to manipulate to achieve a change of the color of the position marker in the text box? The normal foreground attribute changes the actual texts color, but the position marker stays the same color.

WPF style info from external text file

Not sure if this is possible, but I have a WPF application that now has a requirement to be skinnable. Basically, this equates to several key colours and a couple of logos. Is there any way of grabbing the hex values for the colours in defined styles from an external...

Should I be using more than one viewmodel for a database table?

Bit of confusion, which I'm sure can easily be cleared up :). Lets say we have a table called "Contacts". The "Index" view for this table would be a datatable, listing all contacts in the table with First name, email and phone. Now, this would have a viewmodel containing Firstname,...

ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol

I want to know is there anyway to put contentpresenter in itemtemplate of an itemscontrol to display my data. I don't want hard code binding like Text="{Binding username}" cause I am building a custom control, I think ContentPresenter is what I want. But after I tried using contentpresenter, it give...

Add image to the radio button

<StackPanel Name="StpAddDel" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5"> <RadioButton Name="rdbactive" Content="Active" GroupName="actinact" VerticalAlignment="Center" Margin="5,0" Width="50" Height="15" Foreground="Blue"/> <RadioButton Name="rdbinactive" Content="InActive" GroupName="actinact" VerticalAlignment="Center" Margin="5,0" Width="60" Height="15" Foreground="Blue"/> <Button Name="BtnAdd" Height="20" Width="20" Margin="5,0" Template="{StaticResource AddImgBtnTemplate}" />...

MahApps - How to disable automatic uppercase of default button

I have started to introduce MahApps.Metro (really awesome) in my WPF application and my favorite button is the default. The problem is that it puts all my text in uppercase and I don't want it.

Change Background image in WPF using C# [duplicate]

This question already has an answer here: Change WPF window background image in C# code 3 answers I'd like to change the background image of my WPF application by a button. I know how to do it using WindowsForms, but in WPF I failed. I found a solution already,...

WPF: 2 different label sizes in particular order alignment

Please take a look at this picture: I try to create same label with 2 sizes: <Grid> <Label Content="11" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="50" /> <Label Content="%" HorizontalAlignment="Right" FontSize="20" VerticalAlignment="Top"/> </Grid> But currently this is not like the picture: ...

WPF routedevent storyboard begin only if height is zero

I have the following XAML for a border trigger that uses a routed event <Border.Triggers> <EventTrigger RoutedEvent="MouseLeftButtonUp" EnterActions=""> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames BeginTime="0" Duration="0:0:0.4" Storyboard.Target="{Binding ElementName=messageWriterDefinition}" Storyboard.TargetProperty="Height"> <DiscreteObjectKeyFrame > <DiscreteObjectKeyFrame.Value> <GridLength>20</GridLength> </DiscreteObjectKeyFrame.Value>...

Images not appearing on WPF form when loading asynchronously

I'm attempting to display (in a ListBox with a custom DataTemplate) a series of BitmapSource frames (thumbnails) extracted from a multi-page tiff image. When I process the tiff on the UI thread, and either directly add the images to a listbox's item collection or add them to a bound ObservableCollection,...

Aligning StackPanel to top-center in Canvas

I'm trying to create an application which is supposed to measure quick reaction performance of it's user. The application starts up in full-screen mode and resizes it's elements accordingly to the screen resolution. The project was strongly inspired by training_aim_csgo2 map. It's mostly done, but here is the problem: I...

Validate a field only if it is populated

I am having a problem with validating phone numbers. In our system we have two phone numbers which you can store. The problem I am having is that these are optional fields. So I want it to validate the phone number IF and only IF the user has tried to...

Binding string lists into wpf listview returns BindingExpression path error

I've two string lists declared as below: Config.cs: public class AgentSkills { public List<string> agentSkillsNameList=new List<string>(); public List<string> agentSkillsLvlList=new List<string>(); } I retrieved the strings from an XML and added them to the lists as below: Config.cs: foreach (XmlNode skillNameNode in skillNameNodeList) { agentSkills.agentSkillsNameList.Add(skillNameNode.Attributes["value"].Value); } foreach (XmlNode skillLevelNode in skillLevelNodeList)...

while Inherit style in WPF it affect parent style

In WPF i have a style for the control like below, <Style TargetType="local:CustomControl"> <Setter Property="Background" Value="Transparent" /> <Setter Property="BorderBrush" Value="Gray" /> <Setter Property="BorderThickness" Value="0,0,0,1" /> <Setter Property="Padding" Value="3,0,3,0" /> <Setter Property="IsTabStop" Value="False" /> <Setter Property="VerticalContentAlignment" Value="Center" /> </Style> Now i need to override customcontrol border for some other place like...

Animation Methods, Simplification and Repairing

Context I'm kinda new at animating WPF stuff, but I've played around with a library or two and I "had" an animation that I used with the Window control in WPF, this is an example of that method, keep in mind that this method works: public void AnimateFadeWindow(object sender, double...

Adding table header to Listview with DataTemplate in XAML

In my Xaml I'm binding some data from a wcf. I don't know how to add some table headers to the columns. Also the data in the columns is not well aligned, I'm thinking it's because of the ColumnDefinition Width="auto". I want the columns to be aligned like in the...

How do I provide a collection of elements to a custom attached property?

I found a few examples online, and a few questions and answers here, but I just can't get it to work. I need a custom attached property that can take one or more target elements. For example... <ListView> <dd:MyDragDrop.DropBorders> <Binding ElementName="brdOne"/> <Binding ElementName="brdTwo"/> <Binding ElementName="brdThree"/> </dd:MyDragDrop.DropBorders> </ListView> I've also had...

finding file in root of wpf application

I'm trying to load a file with pack://application: The file is situated in the root of my project but I keep getting a null reference error. However When I do an absolute reference it finds the file and loads just fine. What am I missing here? This doesn't work var...

How to draw something in DrawingVisual with millimeter unit instead of pixels?

I'm trying to draw something in a System.Windows.Media.DrawingVisual but I need to draw thins in millimeter unit. How can I do that?

TextBlock hosted inside StackPanel/Grid won't Wrap

How do I make TexBox with an extremely long text wrap when it's placed inside StackPanel/Grid?

TwoWay Binding is not working if Binding is changed from DataTrigger

I have the following DataTemplate for my Tool Bar Items: <DataTemplate DataType="{x:Type viewModels:PopupContextActionViewModel}"> <Grid> <ToggleButton Name="ToggleButton"> <ContentControl Template="{Binding Icon, Converter={StaticResource NameToResourceConverter}}" Margin="5" /> </ToggleButton> <Popup Name="ContextActionPopup" StaysOpen="False" AllowsTransparency="True" IsOpen="{Binding ElementName=ToggleButton, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <Border...

WPF custom button

I start to learn WPF and there is something that is still unclear for me: i created new Style for button: <!-- no border button style --> <Style x:Key="NoBorderButton" TargetType="Button"> <Setter Property="Foreground" Value="White" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="BorderThickness" Value="0" /> <Style.Triggers> <Trigger Property="Control.IsMouseOver" Value="true">...

C# XAML - How to add a combobox to some datagrid ROWS but not others?

I'm using a key/value observable collection to hold data which is represented in the view by a two column datagrid. Some key values contain a list of items and other key values contain a single string value. Using the below code snippet I'm able to display those key values with...

C# Delete Row with Dynamic Textbox/Button/Grid

I've tested some thinks with Dynamic Textboxes and Buttons, Adding Items to my Grid works very well, but if I want to Delete it there are some Bugs, sometimes 1 Row is empty and my Add Button disappears or my Program crashs. What did I wrong or what did I...

System.Windows.Interactivity must be referenced in the main project

So I have a WPF project and my interface in a different project than the main one. I went to reference System.Windows.Interactivity, but it would not work. Not until I added it as a reference to the main project as well... This is the first time this has ever happened...

WPF maximize main window with center for application

i have WPF application and i want to maximize main window. i tried the below code but the issue is that the window is maximized but not centered. i want the window to be maximized as i maximize window with mouse click. my code is: mainWindow.Height = SystemParameters.MaximizedPrimaryScreenHeight; mainWindow.Width =...

Is it possible to concactenate a DataBound value with a constant string in XAML DataBinding?

To bind a value to a TextBlock we use the following syntax to display an <ItemName> property of a bounded object. <TextBlock Text="{Binding Path=ItemName}" /> But is there a syntax to use the above tag to concatenate the constant string 'Item' with the databounded property, in order display something like:...