FAQ Database Discussion Community


Animation Methods, Simplification and Repairing

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

WPF maximize main window with center for application

c#,wpf,window
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 =...

Images not appearing on WPF form when loading asynchronously

c#,wpf,multithreading,listbox,backgroundworker
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,...

WPF. Change DataContext on event binding to access code-behind on a MVVM project

wpf,mvvm,code-behind,datacontext
i'm developing a WPF application with MVVM. At the XAML code i have a Grid with its DataContext pointing to a ViewModel, and i need to know if it is possible to change the DataContext at runtime to access an event at its code-behind. Code-behind for the view: public partial...

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

c#,wpf,printing
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...

Microsoft Band and WPF

.net,wpf,dll,microsoft-band,.net-core
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...

How to open a WPF Popup when RadioButton checked?

wpf,popup
I have a RadioButton and a Popup. I want to open Popup when checked RadioButton and close Popup when LostFocus of it, without unchecked RadioButton. I use this code. <StackPanel> <RadioButton x:Name="RadioButtonSave" IsChecked="{Binding IsSave}">Save</RadioButton> <RadioButton x:Name="RadioButtonNotSave" LostFocus="RadioButtonNotSave_OnLostFocus" IsChecked="{Binding IsSave,Converter={StaticResource ToNegativeConverter}}">Not Save</RadioButton> </StackPanel> <Popup x:Name="Popup" IsOpen="{Binding...

How to bind and refresh UserControl binding in WPF?

c#,wpf,mvvm,data-binding,user-controls
I'm trying to do a simple OneWay binding for a user control, but I honestly don't understand why some parts aren't working. To be simple, I created a WPF standard UserControl with some dependency properties. In my main window, I hide/display the UserControl depending of some events, and I bound...

JSON Deserialization Exception

c#,json,wpf
I made a code to parse this JSON I've generated the class with JSON2C#: public class Link { public string self { get; set; } public string soccerseason { get; set; } } public class Self { public string href { get; set; } } public class Fixtures { public...

WPF: 2 different label sizes in particular order alignment

wpf,alignment,label
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: ...

Choose Style depending on property

c#,wpf,styles,datatrigger
Is it possible to set the Style Property (of a Button for example) from within a DataTrigger on the same control? I would like to define my Default-, MouseOver- and Selected-Styles as resources to reuse them later on. However handling MouseOver (and other) events seems to be usually done by...

tool tip content change getting applied to all elements

wpf,tooltip,gridsplitter
I am creating an application in which I am creating grid splitters dynamically and applying style in the code. The style also sets the tooltip for these gridsplitters. I am using tool tip to display the width of controls and dynamically updating them when resized. When i am changing content...

How to access file from another function

c#,wpf,button
I'm currently working on a C# WPF application which looks something like the following. What I am trying to do is this, the first button, when pressed, basically opens up a browse dialog box where you can select multiple files. I want access to those paths inside my other button...

Binding string lists into wpf listview returns BindingExpression path error

c#,wpf,listview,data-binding
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)...

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}" />...

Change ImageBrush Imagesource programmaticaly with conditions (WPF)

c#,wpf,binding,imagesource,imagebrush
maybe that question was asked 100 times but can you help please I searched everywhere but can't find a normal answer. I got such xaml <Window x:Class="Imagebind.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Background="#FF3F3B51"> <Window.Resources> <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle"> <Setter.Value> <Style>...

Setting App.xaml-resources' value from codebehind

c#,wpf,xaml
I implemented a theme system for my program, and I read the theme from a file at startup. Basically in my App.xaml I have a bunch of <Colors/> with specific keys which I set the value of in code-behind when starting the program in App.xaml.cs.Main(); Here's what it looks like:...

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

c#,wpf,binding
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...

WPF Listbox Collection custom sort

wpf,sorting,listbox,compare,collectionview
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...

TwoWay Binding is not working if Binding is changed from DataTrigger

wpf,datatemplate,datatrigger,2-way-object-databinding
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...

Datagrid inside a Custom control is not updating

c#,wpf,xaml,datagrid
In my Custom Control that have a DataGrid and two buttons, one for add rows in this DataGrid and other button to remove elements. (because of my reputation I can not post an image here, sorry!) :-( My Custom Control code behind: /// <summary> /// Interaction logic for UserControl1.xaml ///...

finding file in root of wpf application

c#,xml,wpf,visual-studio,relative-path
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...

WPF : How to bind Button's visibility inside ListBox ItemsControl using selecteditem information ?

c#,wpf,listbox,itemscontrol,selecteditem
I have a list box binds to a ObservableCollection of Items. Each listboxItem contains a few textblocks and a few buttons. I would like to show the buttons inside the listboxItem only when the listbox item is selected or hightlight. If the listbox item is not highlighted, the button should...

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

c#,wpf,xaml,datagrid,combobox
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...

Changing color of positionmarker/caret

wpf,wpfstyle
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.

Zoom into ListView contents without also scaling scroll bars

c#,wpf,xaml,scaletransform
I have a GridView in a ListView. I want to add a Ctrl+MWheelUp zoom to the contents. I've achieved the zoom part using a ScaleTransform with the below code, however, as this is applied to the ListView as a whole, it also scales the scroll bars. Ideally, I'd like scrollbars...

WPF MVVM custom Sorting issue

c#,asp.net,wpf,sorting,mvvm
I am trying to create custom sorting WPF Data Grid. I have did database call on every sorting. I have used MVVM for this. Issue is I am always getting Sort Direction of column always null on sorting event when I make DB Call. If I remove UpdateData method from...

Filtering ObservableCollection with ICollectionView

c#,wpf,xaml,mvvm,data-binding
I have ObservableCollection binded to dataGrid and now I want to filter the presented data I see that I need to use ICollectionView but I am not sure how to add ICollectionView with my MVVM pattern. My code simplified looks following: public class MainViewModel : ViewModelBase , IBarcodeHandler { public...

WPF/XAML ResourceDictionary with blank space

c#,wpf,xaml
I am using af ResourceDictionary for translating <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib"> <System:String x:Key="NumStartsTotal">Total: </System:String> </ResourceDictionary> I access it like this: <TextBlock Text="{DynamicResource NumStartsTotal}" /> I would like the output to be "Total: " (with the blank space), but it comes out "Total:" (without the blank...

WPF/MVVM setting UserControl.DataContext in XAML results in Object reference not set?

wpf,mvvm
Whenever I paste the UserControl.DataContext portion of the code below, I get "Object reference not set" in the designer. I'm pretty convinced it's something inside the view model, but I think it has to do with binding because it runs fine... When the view model loads it makes a call...

How can i make this CommandParameter work?

c#,wpf,xaml,binding,commandparameter
I've been learning WPF in college this semester but there are still some things I do not fully understand. I have the following code: <UserControl x:Class="Reversi.SquareControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="48" d:DesignWidth="48"> <Button Command="{Binding Place}"...

listview with checkbox get selected row index

c#,wpf,listview,checkbox
here is my problem , i have a listview with checkbox , and i want to get the index of the row which is selected i want to get the index of the row to disable this row after validation i try different method CheckBox cbx = sender as CheckBox.tag;...

Aligning StackPanel to top-center in Canvas

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

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

c#,wpf,printing,drawingvisual
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?

WPF Rotate an Image and align it

wpf,xaml,rotation,rendertransform
I've an Image component where I want to rotate the source : <Image Name="ImageTarget" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Uniform" RenderTransformOrigin=".5,.5"> <Image.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="{Binding Main.BindedViewMode, Converter={StaticResource ImageSizeConverter}}" /> <ScaleTransform ScaleY="{Binding Main.BindedViewMode, Converter={StaticResource ImageSizeConverter}}" /> <RotateTransform Angle="-90" /> </TransformGroup>...

EntityFramework 6 / SqlCe 4 SaveChangesAsync()

c#,wpf,multithreading,entity-framework,sqlce
I have the following method running in a non-GUI thread within my application: private async Task PerformContextSubmitAsync() { try { await DataContextProvider.GetDefaultContext().SaveChangesAsync(); } catch (Exception ex) { Log.Error("Error performing context submit", ex); } } Which is called like this: await PerformContextSubmitAsync(); The application is a WPF/Prism based application so I'm...

Open popup at the location of the button clicked

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

Refactoring INotifyPropertyChanged Setters

c#,wpf,inotifypropertychanged,getter-setter
I am sick to death of writing INPC setters like this: public string Label { get {return _label;} set { if (_label == value) return; _label = value; NotifyPropertyChanged(() => Label); } } I'd like to refactor the setting of the field the same way I did INPC; I'd like...

WPF 4.5: How to create child thread and continue task to UI main thread?

c#,wpf,background-process,caliburn.micro
I use WPF 4.5 and MVVM Caliburn Micro and have following WPF code: public class MainViewModel: Screen { public MainViewModel() { if (!ConnectServer()) { Console.WriteLine("Connection failed"); return; } // Following method can only be run if server connection established ProcessThis(); } } My code above has only one chance to...

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

How to update progress bar while working in the UI thread

c#,wpf,treeview
I have a ProgressBar and a TreeView. I populated the TreeView with a bunch of data, once it is applied I run through the visual tree of the TreeView basically forcing it to generate each of the TreeViewItems. I would like the ProgressBar to show how this is progressing. This...

Setting binding on usercontrol to mainwindow's ViewModel

.net,wpf,xaml,mvvm,data-binding
I have following user control <UserControl x:Class="Station.Controls.FilterTraceDataControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"> <TextBox x:Name="PartNumbTextBox" Width="120" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="5,0,0,0" Height="25"/>...

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

wpf,chromium-embedded
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...

Bind Control to Two properties

wpf,binding
Using MVVM pattern and WPF, I would like to bind my controls to two properties. Let's say I have a label that is bind to property on VM1 and I would like to bind it as well to the property on VM2 to send received value from VM1 to VM2....

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

Validate a field only if it is populated

c#,wpf,idataerrorinfo
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...

Items inside custom panel not getting arranged properly

c#,wpf,xaml
Hello I need a view with multiple columns and variable height rows. I have written a custom WrapPanel which is working properly if its children are explicitly given. The problem arises when I provide an ItemsControl with UserControl in the DataTemplate as the WrapPanel's child. My CustomWrapPanel: public class NewsFeedPanel...

ItemsSource bind to collection stays empty

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

Get rid of Visual Studio Namespace error message

c#,.net,wpf,xaml,namespaces
this is unfortunately a very beginner question: I am doing the very simple WPF tutorials and I am stuck on a namespace problem. I want to do a simple hierarchical treeview binding on a custom object according to the tutorial. I put the object into a custom namespace "MyNameSpace" and...

Fastest way to read very large text file in C#

c#,wpf,large-files
I have a very basic question. I have several text files with data which are several GB's in size each. I have a C# WPF application which I'm using to process similar data files but nowhere close to that size (probably around 200-300mb right now). How can I efficiently read...

WPF 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.'

c#,wpf,nuget,mahapps.metro
My application runs fine in VS 2010 but when I copy the executable from the bin folder to another location I get this error: 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.' Line number '15' and line position '23'. Did a bit of testing and found out that if I include the...

Validation on Radio Buttons

c#,wpf,validation,data-binding,radio-button
I'm not really sure how to word this, so here goes. I've got some radio buttons on a form in my WPF application which get validated. They're basically a required field for this form. When I start to fill in the form, both radio buttons are marked with a red...

Change Background image in WPF using C# [duplicate]

c#,wpf,image,background,resources
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 DataGrid Trigger on cell content

c#,wpf,datagrid,triggers
I have a datagrid than contains value comes from a stored procedure. All values are set Bold as FontWeight. I'd like to make the text normal when the cell content is equal to 0. How can I do that with a trigger? I do that but seems not working <DataGrid.CellStyle>...

How to get the appropriate ComboBox Tag

c#,wpf,combobox
I'm trying to get the Tag associated to a value of ComboBox like this way: var league = ((ComboBoxItem)this.League.SelectedValue).Tag.ToString(); Console.WriteLine(league); The compiler show me a Invalid Cast Exception I only want to get the associated Tag of the selected value by user, in particular: (combobox value and Tag) -Italy (item)...

WPF PRISM - Display multiple pop-up view on the same time

wpf,navigation,prism,regions
My Shell Window contains a secondary pop-up region from the Stock Trader RI demo application infBehaviors:RegionPopupBehaviors.CreatePopupRegionWithName="{x:Static inf:RegionNames.SecondaryRegion}" I am activating my views using the regionManager's RequestNavigate method: regionManager.RequestNavigate(RegionNames.SecondaryRegion, new Uri(FooView, UriKind.Relative)); Everything works fine if I work just with a single View. However in my case I want to have...

C# Delete Row with Dynamic Textbox/Button/Grid

c#,wpf,button,dynamic,textbox
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...

WPF: static INotifyPropertyChanged event

wpf,binding
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...

WPF expander not expanded above buttons make buttons unclickable

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

WPF: why my slider not show the minimum value on my label

wpf,slider,styles
<Grid Margin="405,192,170,450" > <Slider Name="speedSlider" Value="1" Style="{StaticResource SliderStyle}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Minimum="0" Maximum=" 50" TickFrequency="5" TickPlacement="None" Width="160"/> <Label Name="lblSliderSpeed" Content="{Binding ElementName=speedSlider, Path=Value, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" ContentStringFormat="{}{0:#}"/> </Grid> My label show the current slide...

TextBlock hosted inside StackPanel/Grid won't Wrap

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

Why BindingFlags are called so?

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

Add image to the radio button

c#,wpf,xaml
<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}" />...

HorizontalContentAlignment does not appear

wpf,xaml
I have the following code in my .xaml: <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Background="Yellow" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,2,2,0" Name="MainButtonsPanel" Width="100" > <Button Name="ButtonSaveChanges" Background="LightGray" Width="100" Height="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}" Command="{Binding MyCommand}" CommandParameter="{Binding}" Visibility="Visible" /> <Button Name="ButtonEdit" Background="Gray" Width="100"...

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

c#,wpf,mvvm
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,...

WPF, DataGrid, clicked item/row does not highlight (blue background)

c#,wpf,linq,datagrid
Here is the DataGrid XAML: <DataGrid CanUserAddRows="False" AutoGenerateColumns="False" Height="501" HorizontalAlignment="Left" Margin="6,6,0,0" Name="dataGridTrades" VerticalAlignment="Top" Width="574" SelectionChanged="dataGridTrades_SelectionChanged"> <DataGrid.Columns> <DataGridTextColumn Header="ID" Binding="{Binding TradeID}" IsReadOnly="true"/> <DataGridTextColumn Header="Account" Binding="{Binding AccountName}" IsReadOnly="true"/> <DataGridTextColumn Header="Card Name" Binding="{Binding...

Textbox doesn't keep selection on binded list update

c#,wpf,textbox,selection
In my ViewModel i've got an ObservableCollection of string that contains all messages received from ethernet: public ObservableCollection<string> Messages { get; set; } And i binded it to a texbox in the view with a converter: <TextBox Text="{Binding Messages, Converter={StaticResource ListToStringConverter}}" HorizontalAlignment="Center"/> my converter is a simple string finalStr; foreach(var...

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

BooleanToVisibilityConverter works on Textblock and not on UserControl

wpf,xaml,binding,windows-phone-8.1
I'm working on a windows phone project. There is something i don't really understand about my xaml. Here it is: <Page x:Class="CitiBox.MainPage" 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:converters="using:CitiBox.Converters" xmlns:views="using:CitiBox.Views" mc:Ignorable="d" Background="{ThemeResource...

return to previous window on WPF

c#,wpf
I'm new to WPF and couldn't find an answer to to this issue: I have 3 windows I want to navigate between- MainWindow -> Window1 -> Window2 On cancel button click on Window2 I want to return to Window1. I found this code to navigate between 2 windows, but not...

Call controls inside view(xaml file) in viewmodel

wpf,vb.net,mvvm
I want to call controls inside view like button and item template inside viewmodel. Please tell how can I do that. My view contains following <ItemsControl Name="cDetails" Width="395" ItemTemplate="{DynamicResource Test}" ItemsSource="{Binding ViewModels}" Visibility="{Binding IsLoaded, Converter={StaticResource visibilityConverter}}"> <Button Name="btnComplete" Grid.Column="1" HorizontalAlignment="Center" Command="{Binding AuditCommand}" CommandParameter="1"> Complete </Button> Please tell how can I...

MahApps - How to disable automatic uppercase of default button

wpf,mahapps.metro
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.

orderby () containing numbers and letters

c#,wpf,linq,linq-to-sql,sql-order-by
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...

CollectionView: Filter does not work when binding to e. g. ListBox

c#,wpf
I have some sort of cascaded containers that contain notes, where there is one master container, that contains all notes. The notes containers are made in a tree like hierarchy that get more specific the deeper you are in tree-structure. The reason why I have only one list has to...

Change two lists simultaneously

c#,wpf
In my application model I have a list of strings. In my view model I have an ObservableCollection<string> which is initialized with a list from my model. I want to synchronize the list with my observable collection so when we change it, it also changes the list. I came up...

Bind a custom type property to a custom control

c#,wpf,data-binding
I am trying to bind to a user control a property of a custom type (in our exemple, let's call it DataContextOne). This custom type is composed of two strings. I then have a user control to which I want to bind this custom type. The weird thing is that...

Adding table header to Listview with DataTemplate in XAML

c#,wpf,xaml,listview,windows-runtime
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...

WPF Navigation using MVVM

c#,.net,wpf,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 bindings do not pick up any changes

c#,wpf,xaml,mvvm,inotifypropertychanged
In my WPF application, I have some properties which I have bound to the XAML counterpart, but for some reason do not get set whenever their values change. I have implemented the INotifyPropertyChanged interface as well as set my DataContext for this View too, and it is still not picking...

How to get data from combobox from datagrid in WPF?

c#,wpf,xaml
I have been looking for a way to get data out from this datagrid combobox that i made. Specifically the selected value of every combobox from columns. I am new to WPF and would be really grateful if someone would help. Thanks XAML: <DataGrid x:Name="tb" Margin="5,51,5,5" ItemsSource="{Binding}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn...

WPF ObservableCollection two way binding XML file

c#,xml,wpf
I want to bind an ObservableCollection to an XML file. Before the multiple replies of You should bind your DataGrid, ComboBox, etc.. directly to the XML file Please note that the ObservableCollection already exists and is already being bound to DataGrid, ComboBox etc... Re-writing all that code doesn't sound like...

Custom WPF DataGrid with optional button column

c#,wpf,xaml,datagrid,custom-controls
I am creating a custom DataGrid control which has a property, ShowCloneColumn. If you set this property to true the DataGrid should add another column with a Button. The class I've created derives from DataGrid and implemented a Dependency Property, ShowCloneColumn. public static readonly DependencyProperty ShowCloneColumnProperty = DependencyProperty.Register("ShowCloneColumn", typeof(bool), typeof(CloneRowDataGrid),...

WPF Program reopens by itself

c#,wpf
While opening program not from Visual Studio, but directly from the bin\Debug\Program.exe, the program simply closes after approx. 10 seconds and then reopens itself again (but it does not close itself again second time). This happens every single time. I don't know why this happens, tried to check my Antivirus,...

Setting border size on button on mouse over in WPF

wpf
I am trying to set the border colour property on a button when user hovers on it. Currently I am using following XAML. <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="#FF0081a7"/> <Setter Property="BorderBrush" Value="White"/> <Setter Property="BorderThickness" Value="2,2,2,2"/> <Setter Property="Foreground" Value="#FFffffff"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border...

ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol

c#,wpf,itemscontrol,contentpresenter
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...

Can not get Databinding to work (I Have read many posts and can not figure out what I am doing wrong)

c#,wpf
I have created this base class for INotifyPropertyChanged... namespace BASECLASSES.HelperClasses { public class NotifyPropChangedBase : INotifyPropertyChanged { /// <summary> /// The propertyChanged Event to raise to any UI object /// </summary> public event PropertyChangedEventHandler PropertyChanged; /// <summary> /// The PropertyChanged Event to raise to any UI object /// The event...

Overlapping Items in WPF ItemsControl

c#,wpf,xaml,user-interface,datatemplate
I am having a problem with DataTemplates used in a WPF ItemsControl. I want to be able to "bring forward" any of the items in the list so that they are on top of everything else in the list, but haven't had any luck. Here's a simple example that illustrates...

WPF AutocompeteBox in datagrid Cell does not work properly

wpf,datagrid,autocomplete
I am testing the WPF AutoCompleteBox control in datagrid cell. I met two problems: 1) when i navigate to the autocomplete cell , it does not automatically switch to edit mode, 2) When I switch into edit mode and I type something, the list of suggesstions doesn’t appears and I...

Style vs inline property setting in silverlight with a custom control

c#,wpf,xaml,silverlight
I have a custom silverlight control that is pretty much a glorified text box. I have some properties in it I need to be able to set from the XAML in silverlight, so for each property I have created something like this: public bool UseCustomTooltips { get { return _useCustomTooltips;...

Structure of WPF DataGrid - change cells depending on value

c#,wpf,datagrid
I did bind an Object to a DataGridTextColumn and would like to reference one of its properties from within the corresponding CellStyle. I assumed that each cell of this column would contain an instance of MyObject. However I can't find a reference to the Object from within the DataGridCell (I...

WPF: after add WPF Toolkit DLL

wpf,charts,wpftoolkit
After add rrr DLL i am looking at this tutorial. Do i need to add some reference in my XAML in order to find chartingToolkit:Chart ?

Images aren't displayed in WPF ListBox

wpf,data-binding,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>:...

WPF style info from external text file

wpf,vb.net,styles
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...

WPF custom button

wpf,button,styles
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">...

HttpClient returning special characters but nothing readable

c#,wpf,async-await,httpclient
I am trying to download a webpage using async and await and HttpClient, but am getting only a string full of special characters... Code is like.. static async void DownloadPageAsync(string url) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml"); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate"); client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64;...

In WPF how can I control whether another button clicked

c#,wpf,button,mouseevent
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...

WPF add new Slider style cause XamlParseException

wpf,slider,styles
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...

Converting InkCanvas Strokes to a Byte Array and back again

c#,wpf,bytearray,converter,inkcanvas
I am working on a program which converts the inkcanvas strokes to a byte array for encryption and then saves it in a txt file. Essentially I need to convert a byte array to inkcanvas strokes. I have the first half of the code done (which converts the inkcanvas strokes...

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

c#,wpf,dll,reference
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...

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