How to create trapezoid tabs in WPF tab control

I tried to find some control templates or solutions for this problem on internet, but I didn’t find any “acceptable” solution for me. So I wrote it in my way and here is an example of my first (and last=)) attempt to do it: <Window x:Class=”TabControlTemplate.Window1″ xmlns=”” xmlns:x=”” xmlns:src=”” Title=”Window1″ Width=”600″ Height=”400″> <Window.Background> <LinearGradientBrush StartPoint=”0,0″ … Read more

Open directory dialog

You can use the built-in FolderBrowserDialog class for this. Don’t mind that it’s in the System.Windows.Forms namespace. using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { System.Windows.Forms.DialogResult result = dialog.ShowDialog(); } If you want the window to be modal over some WPF window, see the question How to use a FolderBrowserDialog from a WPF application. EDIT: If … Read more

How to access datagrid template column textbox text WPF C#

To find a control in a DataGrid template column, you should use FindChild(): public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject { if (parent == null) { return null; } T foundChild = null; int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, … Read more

Select ListBoxItem if TextBox in ItemTemplate gets focus

You can trigger on the property IsKeyboardFocusWithin in the ItemContainerStyle and set IsSelected to true. <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}”> <Style.Triggers> <DataTrigger Binding=”{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}” Value=”True”> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty=”(ListBoxItem.IsSelected)”> <DiscreteBooleanKeyFrame KeyTime=”0″ Value=”True”/> </BooleanAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> </DataTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> You could also use a Setter instead of a single frame animation but … Read more

Binding WPF DataGrid to DataTable using TemplateColumns

Edit: Updated to reflect the input of Aran Mulholland (see comment) Apparently the DataGrid is passing the entire DataRowView to each cell. That’s why the binding doesn’t work. Your DataTemplate expects the DataContext to be of type MyData, but instead it is of type DataRowView. My proposed (somewhat hack-ish) workaround to get the DataContext you … Read more

Clicking HyperLinks in a RichTextBox without holding down CTRL – WPF

I found a solution. Set IsDocumentEnabled to “True” and set IsReadOnly to “True”. <RichTextBox IsReadOnly=”True” IsDocumentEnabled=”True” /> Once I did this, the mouse would turn into a ‘hand’ when I hover over a text displayed within a HyperLink tag. Clicking without holding control will fire the ‘Click’ event. I am using WPF from .NET 4. … Read more