FAQ Database Discussion Community


WPF : Custom Button

wpf,xaml,button,wpf-controls
I try to edit style in wpf like this : which allow the user design, like this but when i try to create my own style there is chrome layer not Template and I can not create my own button, I can only modify simple value like brush , .........

Add stack panel when check box is checked

wpf,wpf-controls
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) {...

Attach to Event of Sibling Control in Custom WPF Control Initialization

wpf,wpf-controls
I am trying to create a WPF custom slider control that acts as a scrollbar for a Listview. I'm doing this by putting the name of the listview in the Tag attribute of my custom slider and then using the slider's OnValueChange event to scroll the listview. This works great,...

Replicate default mouseover background color when a button is pressed

wpf,wpf-controls
I am building a wpf ribbon application. When certain buttons are clicked on, I would like the background to remain "lit up" like when the mouse is over it. I don't want to change the default mouseover color, I just want to replicate it when the button is pressed for...

Making a progress bar update in real time in wpf

c#,wpf,wpf-controls
I'm having some trouble making the progress bar show the updates in real time. This is my code right now for (int i = 0; i < 100; i++) { progressbar1.Value = i; Thread.Sleep(100); } But for some reason the progress bar shows empty when the function runs, and then...

ListBox inside a ListBoxItem template

wpf,wpf-controls,.net-4.5
I have a ListBox with the following ItemTemplate: <DataTemplate> <StackPanel> <TextBlock .... /> <ListBox .... /> </StackPanel> </DataTemplate> I would like to forbid the user to Select an item in a child ListBox, and that when user clicks on the child ListBox, a parent ListBox SelectedItem should be set respectively....

Change Background color of grid row when selected

c#,wpf,datagrid,wpf-controls
My itemscontrol is currently loading each row correctly. I am trying to get it to change the background color of each row when the user selects it. <Grid> <Grid.RowDefinitions> <RowDefinition Height="100" /> <RowDefinition Height="30" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid Grid.Row="0"> <Border BorderBrush="#BBBDBF" Background="#F4F4F4" BorderThickness="0,1,0,1"...

Obtaining value from Calendar control without selecting a day

c#,wpf,calendar,wpf-controls
Is there a way (using a Calendar control in Visual Studio WPF) I can obtain a value without actually selecting a day within the control. For example, I have a client that wants the calendar's DisplayMode = Year. And now let's say they select the month of March within the...

Resize Columns of Styled WPF DataGrid

wpf,wpf-controls,wpfdatagrid,wpfstyle
I have DataGrid with custom style, I'm having trouble in re-sizing columns because it only works when the cursor is EXACTLY between the two columns Here's the part of style that sets the DataGridColumnHeader <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="Foreground" Value="White"/> <Setter Property="FontFamily" Value="Segoue UI"/>...

Getting content from WPF GridViewColumn through Button

wpf,wpf-controls
I have a Button within a GridView within a ListView. When the button is clicked, I would like to get the text from the corresponding row of the Grid View for that button. Can anyone help me with the code for this? My XAML is: <ListView Name="resultList" ItemsSource="{Binding}" DockPanel.Dock="Top"> <ListView.View>...

What is the logic behind The order of DockPanel children elements

wpf,user-interface,wpf-controls,dockpanel
I know the order of DockPanel children elements matters. I've read somewhere that layout of a child is determined based on the available space left after all previous children have already been positioned. So for example for this piece of code: <DockPanel> <Button DockPanel.Dock="Bottom" Height="20" Content="MyButton"/> <DataGrid Name="dataGrid" ItemsSource="{Binding CarList.Items}"/>...

EventHandler when item is added to StackPanel?

c#,.net,wpf,wpf-controls
Is there any way I can fire an EventHandler when an object is added to a StackPanel? My objective is to add a mousedown event to the StackPanel objects....

Pausing/Stopping Gif animation in WPF

c#,wpf,wpf-controls
I am using gif animation in WPF application, an external dll WpfAnimatedGif.dll is used for showing the animation. The animation is working properly, but I am unable to pause/stop it on a certain event let say button click, how can I do it, kindly guide me, my xaml code is...

Responsive UI for WPF applications

c#,.net,wpf,wpf-controls
I have been trying to adjust the screen based on different sizes to see if any components are reacting to that. Unfortunately they don't I am not sure what I am missing. And it would be great if anyone can give a direct advice and tips for my example implementation....

using MouseOver in StackPanel WPF

c#,wpf,mvvm,wpf-controls
I have just started learning WPF and trying to hide a StackPanel during MouseOver. Below is the code that I use. I can only see the Panel flickering when mouse is placed on it but, it doesn't hide completely. Am I missing something here? Thanks in advance. <Style x:Key="myStyle" TargetType="{x:Type...

Styles not applying to headless wpf control

c#,.net,wpf,wpf-controls
Goal I have a WPF window with some nested ItemsControls. I need to extract the items into bitmaps but without actually displaying the window. So far, I have gotten through some of the hurdles of rendering the visual tree without displaying the actual window. Problem My problem is that the...

Change text when VisualState is set to “PointerOver”,

wpf,wpf-controls
I am working on ControlTemplate for a Button. This is my current code which changes button's color. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App1.Styles"> <ControlTemplate x:Key="ButtonBrushAnimation" TargetType="Button"> <Grid > <TextBlock x:Name="textBlock" Width="80" Height="30" Text="AAA" /> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates">...

WPF - Need to drag in text from notepad and then call a method

c#,wpf,xaml,wpf-controls
I have a textbox on a WPF app that I want to be able to drag text into from an outside application (notepad++). The PreviewDrop handler works great but when I go to retrieve the text from the text box after the handler is called (myTxtBox.Text) all I get is...

Created storyboard animation but not worikng with rows and colums wpf xaml c#

wpf,xaml,wpf-controls
When checkBox selection is done two buttons will animated i just want to do like that,that grid comes in full view i tried rowspan and columspan but not working don't know how to work with it. comes in full view my animation with connection other side of window. code...

WndProc not called in hosted process in wpf

wpf,wpf-controls,hwndhost
Following the instructions in: How to run an application inside wpf application? and in the walkthrough in MSDN (https://msdn.microsoft.com/en-us/library/ms752055.aspx) I have managed to host my console applications in wpf. (Note: there are more than 2 applications to be hosted) In ControlHost.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using...

Stop TextBox in ScrollViewer from growing with content

wpf,wpf-controls
I have a ScrollViewer with HorizontalScrollBarVisibility set to "Auto" that contains a TextBox. The problem is that when a user enters text, the TextBox keeps growing in order to show the entire content. What do I need to change, so that the TextBox only grabs the available width (but is...

Data binding TextBox to string in code behind fails

c#,wpf,xaml,data-binding,wpf-controls
I'm attempting to bind a string property to a TextBox's Text field in XAML. I am doing this in a UserControl. I've searched StackOverflow and the internet in general and found various related topics, some examples: Binding objects defined in code-behind WPF: simple TextBox data binding I've followed the code...

Enumerating through objects in `ContentPresenter`

c#,xaml,windows-phone-8,wpf-controls
Windows Phone 8.1 I have a custom control with ContentPresenter. When this control is used in XAML page, it is possible to add any type of FrameworkElement there. I want to enumerate through all items in ContentPresenter and act accordingly to what I find there. This is my approach: protected...

Silent print HTML file in C# using WPF

c#,html,wpf,printing,wpf-controls
EDIT: Completely rewrote question and added bounty. Based on many tutorials and stackoverflow questions I can now: Print multiple pages together as one document. Print actual content. Align content correctly on page. Print correct size documents. The solution requires the HTML document to have some white space in the bottom...

WPF routedevent storyboard begin only if height is zero

wpf,storyboard,wpf-controls,routed-events
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>...

Get data from web pages and save locally

wpf,wpf-controls,html-parsing
I start to learn WPF and there is something that is still unclear for me: I want to create app, which can get information from online web sites (e.i. news). How can I parse data from pages? And second question, which is connected first one, How can I save user...

Playing the animation after “FrameworkElement.Loaded” and before “Unloaded” (in ListBoxItem)

wpf,wpf-controls,wpf-animation
I have ListBox: <ListBox x:Name="ListBoxImages" ScrollViewer.CanContentScroll="True" UseLayoutRounding="False" SelectionMode="Extended"/> ListBox style: <Style TargetType="{x:Type ListBox}"> ... <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBox"> <Border Name="Border"> <ScrollViewer Focusable="false"> <WrapPanel ItemWidth="100" IsItemsHost="True"/> </ScrollViewer> </Border> </ControlTemplate> </Setter.Value> </Setter>...

Combo Box 1st item is remained empty in WPF c#

c#,combobox,wpf-controls
I have a combox in my wpf and 2 items called: Send Receive. I want to make the combobox to show a general message(send/receive) when the WPF is loaded up at first time. I tried to apply a string to the Text property in the XAML but it didn't work:...

WPF button property binding to code

wpf,vb.net,xaml,wpf-controls
I am trying to bind ribbon buttons property IsEnabled to code property so I can make it available or not to the user depending on a certain situation. I don't know what I am doing wrong and I can't figure it out Currently I have the following code. The class...

How to use LostFocus as a Command in WPF

wpf,wpf-controls,wpfdatagrid
I am trying to use LostFocus event as Command in DataGridTextColumn and can't find an example on how to use it in WPF. Can anyone help me use it as I am new to WPF. Thank you. My xaml looks like: ` The c# code: public partial class Myogg :...

RichTextBox scroll to end not working when not visible

wpf,wpf-controls,scrollbar,richtextbox,vertical-scrolling
I have a WPF RichTextBox in my application that sits in Grid. It gets updated every second or two as it displays logs (though sometimes there are no logs for up to a minute depending on the load). The grid is not always visible, as it sits in its own...

Button Visibility in WPF at startup

c#,button,wpf-controls,visibility
I have some button that I want them to be hidden when the wpf loads up. I use this: public MainWindow() { mySendButton.Visibility = Visibility.Hidden; myReceiveButton.Visibility = Visibility.Hidden; InitializeComponent(); } But the above generating an error. i think I wrote them not at the right place. Can I get a...

Why Grid is needed predetermined background?

wpf,wpf-controls,wpf-animation
I made in style a button animation. All elements of a button placed in the Grid. But if do not set background in grid, animation does not work correctly. Button: <Grid> <Rectangle Fill="{TemplateBinding Background}" RenderTransformOrigin="0.5,0.5" Margin="5"> <Rectangle.RenderTransform> <RotateTransform x:Name="RotateTransform" Angle="0"/> </Rectangle.RenderTransform> </Rectangle> </Grid> Animation: <ControlTemplate.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <BeginStoryboard>...

Gracefully handling expected BindingExpression errors

wpf,xaml,data-binding,wpf-controls
I have a ComboBox bound to an ObservableCollection where the DisplayMemberPath references an object property Url. My CompositeCollection contains a null item, allowing the user to have an optional selection: <ComboBox Grid.Row="7" Grid.Column="1" Height="24" VerticalAlignment="Top" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedNotificationServer, Mode=TwoWay}" DisplayMemberPath="Url"> <ComboBox.Resources> <CollectionViewSource x:Key="comboBoxSource" Source="{Binding Path=NotificationServers}" />...

while Inherit style in WPF it affect parent style

c#,xaml,styles,wpf-controls
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...

Change ToggleButton for Expander in Wpf when expanding

c#,.net,wpf,xaml,wpf-controls
I want to change the toggler of expander when I collapse and uncollapse. Which means, I want to place an image instead. Is there a simpler way to do that in XAML rather than building ypur own expander template?

getting listbox.selectedindex by clicking on checkbox

c#,wpf,checkbox,listbox,wpf-controls
this is my user template in listbox. i want to have "listbox.selectedindex" on clicking any checkbox of listbox. i want to knw of which row,checkbox is selected.like on click event of checkbox,it should focus the whole selected row. <ListView x:Name="listbox3" Visibility="Visible" Margin="540,168,37,46" IsSynchronizedWithCurrentItem="True" BorderBrush="Black"> <ListView.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Width="200" >...

F# Creating a UserControl Programmatically: Missing Update (keyboard input seem locked)

wpf,f#,event-handling,wpf-controls,dependency-properties
I have tried to create a "UserControl" "By-Code" only, using F# (Vers. 12.0.30815.0 + Framework 4.5) since I prefer this "way" (no mix between C# and F#). NOTE: I have to show multiple properties of a single Class in an Input Form, so this UserControl need to implement Binding capabilities...

Hi.I want to use same menu in different pages in xaml.how to do it?

wpf,xaml,wpf-controls
I have two pages in xaml.in first page(MainWindow.xaml),i create menu.In second page i want to use menu again. Questions: How i do this? ...

Progress bar does not updated wpf? [duplicate]

c#,wpf,wpf-controls
This question already has an answer here: How to correctly implement a BackgroundWorker with ProgressBar updates? 1 answer I am trying to update my progress bar inside contentrendered(object sender, EventArgs e) event. This is my code :- MainWindow.xaml.cs DynamicControls.ProgressBarWindow _progressBarWindow = new DynamicControls.ProgressBarWindow("Please Wait..."); _progressBarWindow.ShowDialog(); XAML <Window x:Class="nk_Image_Converter.DynamicControls.ProgressBarWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"...

Handling different item templates that share the same content

wpf,wpf-controls,.net-4.5
I have two custom ItemTemplates for the ListBox, one for the regular items, and one for the selected item. An example of how would I handle this is: <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="ContentTemplate" Value="{StaticResource Template1}" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="ContentTemplate" Value="{StaticResource Template2}" /> </Trigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle>...

WPF: Synchronize width of all items in ItemsControl

c#,wpf,wpf-controls
Is it possible to adjust the width of all TextBlocks in the WrapPanel to the size of the largest TextBlock within the WrapPanel? The end result should be that the width of the control containing "Some data" has the same width as the control containing "Even more data than before."...

Responsive TextSize in WPF

wpf,wpf-controls
How can I (programatically) set the font size of a TextBlock in a WPF Canvas? The text size should be relative to the canvas dimensions, so that it is centered. This works for my local machine, but displayed on a larger screen, the text is cut off halfway up. double...

Icon does not appear in Windows Taskbar

c#,wpf,wpf-controls
I work on WPF application and I finishing it, but I notice that when I run the application, the application Icon does no appear in Windows task bar ? Although I assigned icon for my application in application properties. Any idea ? Thanks in advance Abdusalam...

C# wpf Ellipse width and height for two points

c#,wpf,wpf-controls,ellipse
I'm trying to draw a circle centered at point2 with radius "r". r's length should be long enough to be the distance between point1 and point2. I drew a picture to illustrate this. How can I calculate the correct width and height of the ellipse to draw it like this...

Custom Control DataBinding wpf

wpf,wpf-controls,custom-controls,dependency-properties
Currently implementing a custom control I would like to bind some Value directly from my viewModel without using xaml. I can do this: <customControls:MyControl MyValue="{Binding ElementName=MyElem, Path=Text}"> <Textbox Text="{Binding Mytext}" /> But not: <customControls:MyControl MyValue="{Binding MyText}"> The controls is defined in a template and inside the Control code my the...

Is it safe to mark a PropertyChangedCallback asynchronous?

c#,wpf,wpf-controls
I have a dependency property on a class, let's call it 'SomethingControl': public static readonly DependencyProperty SomethingProperty = DependencyProperty.Register("Something", typeof(Something), typeof(SomethingControl), new UIPropertyMetadata(SomethingGotSet)); And I have defined the callback method that is being passed into the UIPropertyMetadata constructor as asynchronous: private async static void SomethingGotSet(DependencyObject d, DependencyPropertyChangedEventArgs e) { var...

List not displaying correctly WPF

c#,wpf,xaml,data-binding,wpf-controls
Situation Hey guys, for a program I'm developing I have a getRaces() method: public string getAllBaseRaces() { //string to hold a list of members string strRaces = ""; foreach (BaseRace s in races) { strRaces = strRaces + s.ToString() + "\n"; } return strRaces; } I'm trying to populate a...

How to apply style to a custom control

c#,xaml,wpf-controls
I have a custom control inheriting from ListBox. I have a style for it targeting my custom control. For some reason this style is not working on my custom control. Could you please tell me what I am missing here? Code for style: <Style x:Key="ListBoxStyle" TargetType="local:CustomListBox"> <Setter Property="Background" Value="Red"/> <Setter...

Blink highlight a button according to its value changes

c#,wpf,data-binding,wpf-controls
I have WPF control, it has a list view with many buttons I need those buttons to blink and highlight for a short time when their binded value changes (to Green when value goes up and to red when it goes down). What is the best way doing that?...