datatemplate

WPF: How to set bool to true from DataTemplate for Button?

谁说我不能喝 提交于 2020-01-11 14:07:14
问题 I know it is possible to do this by working with ICommand, but since this is the only place in my whole project where this is needed, I am asking myself, if there is maybe a better solution than implementing RelayCommand and ICommand and an additional method in my otherwise property-only class? Maybe my scenario may help here: I have a ListView which is bound to a list of properties (this is a custom-class I made to display those). I have a button in eacht row of entries, that I want to set

Find TextBox in a DataTemplate

人盡茶涼 提交于 2020-01-06 12:35:12
问题 Have some elements in a DataTemplate that I need to access in a code behind event handler. Below works if the button and the textbox have the same Parent. How would I handle a more complex layout? If there a general way for accessing an element in a DataTemplate? XAML <DataTemplate x:Key="fieldDateTemplate"> <StackPanel> <DatePicker SelectedDate="{Binding Path=FieldValue}" /> <TextBox x:Name="tbFindMe" Text="findME"/> <Button Content="FindTB" Click="FindTB_click" Width="60"

Metro app: ListView ItemTemplate DataTemplate for selected item

别来无恙 提交于 2020-01-06 07:45:10
问题 I created a SplitPage view from canned templates that has the following ListView definition: <!-- Vertical scrolling item list --> <ListView x:Name="itemListView" AutomationProperties.AutomationId="ItemsListView" AutomationProperties.Name="Items" TabIndex="1" Grid.Row="1" Margin="-10,-10,0,0" Padding="120,0,0,60" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" IsSwipeEnabled="False" SelectionChanged="ItemListView_SelectionChanged" ItemTemplate="{StaticResource

Handle an event in a Data Template loaded by XamlReader.Load(xaml) in code-behind

佐手、 提交于 2020-01-06 07:43:48
问题 How can I bind an event to the DataTemplate (which is generated via xamlreader) in codebehind? This is What I've tried string xaml = @"<DataTemplate " + namespaceString + " >" + rowsXaml + "</DataTemplate>"; Debug.WriteLine("Datatemplate is " + xaml); try { var template = (DataTemplate)XamlReader.Load(xaml); return template; } In XAML: <ListView ItemsSource="{Binding Source={StaticResource GroupedRecords}}" formatter:SwipeListHandler.RecordTemplate="{Binding RecordsTemplate}" BorderBrush=

WPF Grid.IsSharedSizeScope in ItemsControl and ScrollViewer

和自甴很熟 提交于 2020-01-06 07:08:00
问题 I'm simplyfying this log viewer. It works mostly as expected, but somehow the column lengths don't share the same size. Here is my code: <Window.Resources> <local:IsGreaterThanConverter x:Key="IsGreaterThanConverter" /> <sys:Int32 x:Key="MaxDisplayLineLength">200</sys:Int32> <Style TargetType="ItemsControl" x:Key="LogViewerStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ScrollViewer CanContentScroll="True"> <ItemsPresenter/> </ScrollViewer> </ControlTemplate> </Setter

Applying style to elements inside a DataTemplate

拟墨画扇 提交于 2020-01-05 11:08:10
问题 I have a UserControl which simply contains a TextBlock and TextBox inside a DataTemplate. This is done in the following way: <UserControl.Resources> <DataTemplate DataType="{x:Type Binding:StringBindingData}" x:Key="dataTemp"> <StackPanel Orientation="Horizontal" Name="sPanel"> <TextBlock Name="txtDescription" Text="{Binding Description}" /> <TextBox Name="textboxValue" Text="{Binding Mode=TwoWay, Path=Value, UpdateSourceTrigger=PropertyChanged}" /> </StackPanel> </DataTemplate> </UserControl

Applying style to elements inside a DataTemplate

时光总嘲笑我的痴心妄想 提交于 2020-01-05 11:08:09
问题 I have a UserControl which simply contains a TextBlock and TextBox inside a DataTemplate. This is done in the following way: <UserControl.Resources> <DataTemplate DataType="{x:Type Binding:StringBindingData}" x:Key="dataTemp"> <StackPanel Orientation="Horizontal" Name="sPanel"> <TextBlock Name="txtDescription" Text="{Binding Description}" /> <TextBox Name="textboxValue" Text="{Binding Mode=TwoWay, Path=Value, UpdateSourceTrigger=PropertyChanged}" /> </StackPanel> </DataTemplate> </UserControl

DataTemplate for ListBox element is not binding at all

ε祈祈猫儿з 提交于 2020-01-05 07:31:15
问题 I have a ListBox element, which purpose is to show the users the activities, that are registered on the Database so that they can choose from them to modify or delete them. After consulting two very useful answers about using DataContext and DataTemplates, I decided to implement that knowledge in my project, unfortunately, it's not working. When I run it and I select the text on the ListBox , I only see: DataTemplate templ = new DataTemplate(typeof(Activities)); as its content, and I didn't

How to set style for ItemsPanel from outside?

半世苍凉 提交于 2020-01-05 07:08:56
问题 I define a style to make all StackPanel green: <Window.Resources> <Style TargetType="StackPanel"> <Setter Property="Background" Value="Green" /> </Style> </Window.Resources> But if I use StackPanel as panel template then it's NOT green: <UniformGrid> <StackPanel /><!-- this one is green --> <ItemsControl> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel /><!-- this one is not --> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </UniformGrid> Why? How to make it also

DataGrid: Help accessing a control defined in a CellEditingTemplate

主宰稳场 提交于 2020-01-04 12:14:42
问题 I am using the WPF DataGrid with a DataGridTemplateColumn. The DataGridTemplateColumn.CellEditingTemplate contains a ComboBox with IsEditable set to 'true'. In my RowEditEnding event handler, I'd like to read the Text property of that ComboBox - the only problem is that I don't know how to retrieve the ComboBox instance within the event handler in order to get to the Text property. For reference, here's my DataTemplate: <!-- ... --> <my:DataGridTemplateColumn.CellEditingTemplate>