datatemplate

WPF MVVM Binding dynamic control in code behind and pass in View

北慕城南 提交于 2019-12-04 06:59:50
问题 I am working on WPF application using MVVM. I have two page. I have multiple UserControls in a page 1, on selection of UserControls from page 1, I want to show that selected userControl in 2nd page. Below are my code. ViewModel Code public RelayCommand<string> OnClickSelectWidgetCommand => new RelayCommand<string>((setUserControlName) => { using (new CursorWait()) { var MyContentControl = setUserControlName; MessageBox.Show(MyContentControl); //How to render UserControl to View? } }, true);

Changing DataTemplate TextBlock Property at Runtime

て烟熏妆下的殇ゞ 提交于 2019-12-04 06:01:57
问题 I have a DataTemplate defined as follows: I am accessing it at runtime using the code below: else { template = (DataTemplate)FindResource("GridViewTextBlockDataTemplate"); var textblock = (TextBlock) template.LoadContent(); textblock.Text = "bye"; //textblock.SetBinding(TextBlock.TextProperty, new Binding("[" + current.Key + "]")); } var column = new GridViewColumn { Header = current.Key, CellTemplate = template }; gridView.Columns.Add(column); } And now I want to change the textblock

WPF MVVM: Setting DataContext of Tab Views

假装没事ソ 提交于 2019-12-04 06:00:26
问题 I have experienced a weird binding behavior that is described here. I did a lot of troubleshooting and I came to the conclusion that the most likely problem lies at how I set the DataContext of each of the tab's view. I have a TabControl whose ItemsSource is bound to a list of ViewModels . MainView: <TabControl ItemsSource="{Binding TabList}"> <TabControl.Resources> <DataTemplate DataType="{x:Type vm:Tab1ViewModel}"> <v:Tab1 /> </DataTemplate> </TabControl.Resources> ... </TabControl>

WPF Pass current item from list to usercontrol

萝らか妹 提交于 2019-12-04 05:01:14
问题 I am binding to an ObservableCollection<Stage> Stages as the ItemsSource for an ItemsControl: <ItemsControl ItemsSource="{Binding Path=Stages}"> Is there any way to pass the current stage object to a usercontrol in an item datatemplate like this: <ItemsControl ItemsSource="{Binding Path=Stages}"> <ItemsControl.ItemTemplate> <DataTemplate DataType="{x:Type local:Stage}"> <local:MyUserControl CustomDependencyProperty="{Binding}" /> </DataTemplate> </ItemsControl.ItemTemplate> The real problem

Data Error 26 with DataTemplate and ItemTemplate

痞子三分冷 提交于 2019-12-04 04:53:45
问题 I have a TabControl with a single specific tab and a collection bound to a collection of VMs, using a different user control. To do this I use a CompositeCollection and DataTemplates defined in the control's resources, selecting correct user control based on the VM type (acting as ContentTemplate). I also set an ItemTemplate to define the tab item's name with binding, but it's not defined in the resource as I guess would conflict with the "ContentTemplate" ones. It works fine, but I see the

WPF TwoWay Binding of ListBox using DataTemplate [duplicate]

若如初见. 提交于 2019-12-04 04:40:38
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to make ListBox editable when bound to a List<string>? I'm trying to set a two-binding between a List named "ListStr" object and a ListBox WPF control. Besides I want the items to be editable, so I added a DataTemplate with TextBoxes expecting that it would modify the ListStr items straight away via TextBoxes. But when I'm attempting to edit one of them, it doesn't work... Any Idea ? PS: I've tried to add

Cant get a control from a TabControl DataTemplate

雨燕双飞 提交于 2019-12-04 03:35:12
问题 I've been googling this for the last 2 days and cant get anywhere, I just cant do anything to any control in a datatemplate of a tabcontrol. First off, the code: private void Window_Loaded(object sender, RoutedEventArgs e) { tabControl1.ItemsSource = new string[] { "TabA", "TabB", "TabC" }; } private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e) { ContentPresenter cp = tabControl1.Template.FindName("PART_SelectedContentHost", tabControl1) as ContentPresenter;

C#/WPF: Get Binding Path of an Element in a DataTemplate

Deadly 提交于 2019-12-04 03:29:35
How can I get the Binding Path of an Element in a DataTemplate? My XAML looks like this: <GridViewColumn Header="Double"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding TotalValues, Mode=OneWay, StringFormat=\{0:0\'0.00\}, Converter={StaticResource GridValueConverter}}" TextAlignment="Right" Width="auto"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Comments" DisplayMemberBinding="{Binding Path=Comments, Mode=OneWay}" Width="auto"/> To get the Binding Path for the "normal" GridViewColumnHeader.DisplayMemberBinding is var

Windows Phone 8.1 App dont see DataType property in DataTemplate

陌路散爱 提交于 2019-12-04 02:50:45
问题 I created new Windows Phone 8.1 project and when I try to set DataType , vs2013 give me in editor error: The property 'DataType' was not found in type 'DataTemplate' . In WPF application I dont have this problem. How to fix it? This is my MainPage.xml: <Page x:Class="App6.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App6" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns

Scroll a new item in a ItemsControl into view

左心房为你撑大大i 提交于 2019-12-04 01:05:03
问题 I have an ItemsControl that is databound to a ObservableCollection . I have this method in the code behind which adds a new model to the list. I would then like to scroll the new item (at the bottom of the list) into view. I think the size of the ItemsControl is not yet updated when I am querying the size, since the ActualHeight before and after the addition of the model is the same. The effect of this code is to scroll to a point slightly above the new item. How would I know what the new