Bind to DependencyProperty of Window

I want to create a CheckBox for toggling the Topmost property of the window. If TopMost was a property of the ViewModel, I’d use this: <CheckBox IsChecked="{Binding Path=Topmost}">Topmost</CheckBox> But Topmost is a DependencyProperty on the Window in which the CheckBox is situated. I tried the following: <CheckBox IsChecked="{Binding Path=Topmost, Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">Topmost</CheckBox> but I… Read More Bind to DependencyProperty of Window

How to bind Enum to Text property of TextBlock in ListBox

I am not successful at getting my DataTrigger to work for binding to enum. Each line in the ListBox is ‘S’, just as in the default Setter XAML: <Window x:Class="BindToEnumTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot; xmlns:d="http://schemas.microsoft.com/expression/blend/2008&quot; xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006&quot; xmlns:local="clr-namespace:BindToEnumTest" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <ListBox Grid.Column="0" x:Name="LBMain" ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Auto"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Grid.Column="0" x:Name="TxtType"> <TextBlock.Style> <Style TargetType="TextBlock"> <Setter Property="Text"… Read More How to bind Enum to Text property of TextBlock in ListBox

How to programmatically set `ContentControl.Content` as the dependency property for a data binding between a Button and a string property

I’m trying to create a simple data binding programmatically in a minimal WPF application. The source is the SourceText property in the SourceClass instance and the target is the Button control: XAML File: namespace notify_on_source_updated { public class SourceClass { public string SourceText { get; set; } } /// <summary> /// Interaction logic for MainWindow.xaml… Read More How to programmatically set `ContentControl.Content` as the dependency property for a data binding between a Button and a string property

Reading a text file with multuple header lines and multiple sections

I have a file that has multiple "header lines" (identical) for each section (ID) and has multiple IDs. see below; IDS: df-1 df-1 df-1 Date/Time L A Z yyy-mm-dd H:M:S in ft/s2 ft 2022-04-28 13:30:00 NA 0 NA 2022-04-28 13:45:00 NA 2.968 NA 2022-04-28 14:00:00 2.427 3.124 22.818 IDS: dat-2 dat-2 dat-2 Date/Time L A… Read More Reading a text file with multuple header lines and multiple sections

Reading a text file with multuple header lines and multiple sections

I have a file that has multiple "header lines" (identical) for each section (ID) and has multiple IDs. see below; IDS: df-1 df-1 df-1 Date/Time L A Z yyy-mm-dd H:M:S in ft/s2 ft 2022-04-28 13:30:00 NA 0 NA 2022-04-28 13:45:00 NA 2.968 NA 2022-04-28 14:00:00 2.427 3.124 22.818 IDS: dat-2 dat-2 dat-2 Date/Time L A… Read More Reading a text file with multuple header lines and multiple sections

WPF – Bind commands to ListBox items?

as the title suggests, I’m My MainWindow.xaml has MainWindowViewModel.cs as its DataContext, and within this ViewModel is an ObservableCollection. In the .xaml file, I added a ListBox as follows: <ListBox ItemsSource="{Binding RoleTypes}"> <ListBox.ItemTemplate> <DataTemplate> <RadioButton Content="{Binding}" GroupName="ClientRole" Command="{Binding SetSelectedRoleCommand, Mode=OneWay}" CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"> </RadioButton> </DataTemplate> </ListBox.ItemTemplate> </ListBox> The issue is that I need to… Read More WPF – Bind commands to ListBox items?

Why I cannot add Items into DataGrid in C#

I’m trying to dynamically add new records to DataGrid. I’m using HashSet to prevent duplicates. But when I want to add objects from HashSet to ObservableCollection, I get the error: Cannot apply indexing with [] to an expression of type ‘system.collections.generic.ienumerable<>. I have implemented IEnumarable. Contructor in AdminWindow.xaml.cs class public AdminWindow() { InitializeComponent(); ObservableCollection<Alert> alertToDataGrid… Read More Why I cannot add Items into DataGrid in C#

How to bind different UI controls to different objects

I have two UI controls whose properties I want to bind to properties of two different objects. Here is my XAML file: <Window x:Class="WpfBindingDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot; xmlns:d="http://schemas.microsoft.com/expression/blend/2008&quot; xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006&quot; mc:Ignorable="d" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize"> <Canvas Width="300" Height="200"> <Slider x:Name="_slider1" Canvas.Left="10" Canvas.Top="10" Width="272"/> <Slider x:Name="_slider2" Canvas.Left="10" Canvas.Top="36" Width="272"/> </Canvas> </Window> And here is my code behind: using System.Windows; using… Read More How to bind different UI controls to different objects