datatemplate

Find Control in DataTemplate with a multi selection listbox

我的未来我决定 提交于 2019-12-24 12:12:06
问题 I have a multi selection listbox where a user can tick multiple items in the list. At the moment I have it so when a checkbox is ticked the ListBoxItem it is within also gets selected: private void CheckBox_Checked(object sender, RoutedEventArgs e) { //Select the Item using the DataContext of the Button object clicked = (e.OriginalSource as FrameworkElement).DataContext; var lbi = LstDistro.ItemContainerGenerator.ContainerFromItem(clicked) as ListBoxItem; lbi.IsSelected = true; } Now I am

Error Implementing Design Time Data Template

我怕爱的太早我们不能终老 提交于 2019-12-24 11:04:25
问题 I want to display dummy data in the design window of a WPF GridView and found a similar example: Answer: Design time data for datatemplate in xaml - Stack Overflow I created a new WPF App (.NET Framework 4.6.1) named WpfDataTemplate and copied in the code snippets from the example into MainWindow.xaml.cs and MainWindow.xaml . All additions are noted in comments with ## . Unexpected Behavior: The line <local:MyMockClass x:Key="DesignViewModel" /> produces the error "Object reference not set to

Accessing elements inside a DataTemplate in a TabItem

我怕爱的太早我们不能终老 提交于 2019-12-24 07:09:16
问题 Well , I have a problem with a function that I get from there [VB.NET] Public Class TreeHelper Public Shared Function FindVisualChildByName(Of T As FrameworkElement)(parent As DependencyObject, name As String) As T Dim child As T = Nothing For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(parent) - 1 Dim ch = VisualTreeHelper.GetChild(parent, i) child = TryCast(ch, T) If child IsNot Nothing AndAlso child.Name = name Then Exit For Else child = FindVisualChildByName(Of T)(ch, name) End

How do you add an Event Trigger to a data template for a business object?

大城市里の小女人 提交于 2019-12-24 05:20:09
问题 I have a custom class named BlinkingLight. I also have a static ObservableCollection BlinkingLightCollection. In the UI, I have a ListBox that is bound to BlinkingLightCollection. In my ListBox I want to essentially display each BlinkingLight object as a custom control that looks like box with an LED light that has an animation that makes the LED look like it just flashed on for a second then goes back to normal. My BlinkingLight class has third party "LED" object that raises an event called

Binding doesn't work when using custom control in DataTemplate

主宰稳场 提交于 2019-12-24 04:53:22
问题 I'm trying to replace a standard control inside ListView DataTemplate with a custom control, but binding doesn't seem to work properly. Here is the definition of the ListView: <Grid> <ListView ItemsSource="{Binding DataItemsCollection}"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="Static text" /> <TextBlock Text="{Binding DataItemText}" /> <BindingTest:CustomControl CustomText="{Binding DataItemText}" /> </StackPanel> </DataTemplate> </ListView.ItemTemplate> <

Handling the same click event in a nested control inside ListBoxItem DataTemplate - WPF

混江龙づ霸主 提交于 2019-12-24 01:54:40
问题 When we have a custom listbox with a defined event-handling for the left-click of the mouse, and also an additional shape inside the ListBoxItem data template which needs to do some action when it is clicked how can we handle these I have a Custom ListBox witch tries to handle the Click event : In the ContentView: <ABC:AListBox ClickCommand="{Binding LaunchCommand}" ...> </ABC:AListBox> In it's datatemplate we have this: <DataTemplate x:Key="ThisListTemplate"> <StackPanel ...> <Border Grid

Handling the same click event in a nested control inside ListBoxItem DataTemplate - WPF

只谈情不闲聊 提交于 2019-12-24 01:54:14
问题 When we have a custom listbox with a defined event-handling for the left-click of the mouse, and also an additional shape inside the ListBoxItem data template which needs to do some action when it is clicked how can we handle these I have a Custom ListBox witch tries to handle the Click event : In the ContentView: <ABC:AListBox ClickCommand="{Binding LaunchCommand}" ...> </ABC:AListBox> In it's datatemplate we have this: <DataTemplate x:Key="ThisListTemplate"> <StackPanel ...> <Border Grid

Binding from resources inside a DataTemplate

假装没事ソ 提交于 2019-12-24 01:04:53
问题 Is there some way to get the DataContext of a DataTemplate to use in bindings within its resources? <DataTemplate x:Key="History"> <ItemsControl ItemsSource="{Binding History}"> <ItemsControl.Resources> <app:BitmapProvider x:Key="Converter" ShowDetails="True" Type="{Binding Model.Type}" /> </ItemsControl.Resources> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" IsItemsHost="True"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate

Datatemplate binding spam Output window with error: Cannot find governing FrameworkElemen

二次信任 提交于 2019-12-24 00:34:18
问题 I have problem System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=48519443); target property is 'Color' (type 'Color') It can be reproduced with following xaml: <Window PreviewKeyDown="Window_PreviewKeyDown" xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" ... > <Window.Resources> <DataTemplate DataType="{x:Type local

Question about Data Template or Style in WPF xaml

可紊 提交于 2019-12-23 19:15:34
问题 I have a textbox that has the following simple XAML (not necessary to read it - just have it for reference): <TextBox Name="m_ctrlUserDeviceType" Style="{StaticResource textStyleTextBox}" Text="{Binding Source={x:Static api:MySettings.Instance}, Path=UserDeviceType, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Validation.Error="TextBox_Error" MinHeight="25" Margin="4" VerticalAlignment="Top" MaxLength="23" VerticalContentAlignment="Center" HorizontalAlignment="Left" MinWidth=