Bind DataTemplate after Task is finished - wpf

I'm looking for a way to bind a datatemplate which is in a resource file that my MainWindow accesses, but only after a Task that is running in the viewmodel has completed.
The idea was to load a lot of data while the view displays with a little progress area... when the progress is done... then the data should be binded... is the dependency property that allows for this?
<DataTemplate x:Key="TabsTemplate">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<UserControls:TabButton Command="{Binding Path=Tab}" Content="{Binding Path=DisplayName}" Template="{Utilities:BindableResource {Binding Path=TemplateResource}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>

Figured it out...
Tabs.GetBindingExpression(ContentControl.ContentProperty).UpdateTarget();
Works perfect after the progress is completed.

Related

WPF/XAML Intuitive UserControl

what steps must be done to make a user control, to work in such order:
<local:MyUserControl ItemsSource="{Binding Items}">
<local:MyUserControl.Items>
<local:MyUserControl.Item Name="{Binding Name}"/>
</local:MyUserControl.Items>
</local:MyUserControl>
I know that for ItemsSource I need to create DependencyProperty, but what for the part which is inside MyUserControl.
Example:
Look below is an example how I used to do it.
This is called MyUserControl
<UserControl>
<Grid>
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Margin="3,3,3,3"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
MainPage:
<local:MyUserControl />
As you can see in this scenario, MyUserControl is not universal, it can be used properly ONLY if I have ItemsSource called Items, and inside of it there is a property called Name.
My Intention is to create flexible MyUserControl.
Thanks in advance.

WPF - How to add textboxes to a wrap panel dynamically when number of textboxes come from a datasource

I need to add textboxes to a wrap panel but the number of textboxes come from a database. How can I do this in XAML binding instead of programmatically.
Thank you in advance
Try something like below code:
<ItemsControl ItemsSource="{Binding NumberOfTextBoxes}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding SomeProperty}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

itemscontrol mouseDragElementbehavior for new items not working

I found this solution Using MouseDragElementBehavior with an ItemsControl and Canvas by Jörg Reichardt. But it doesn't work for me.
This is my code:
<ItemsControl ItemsSource="{Binding CardCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="White" AllowDrop="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}">
<i:Interaction.Behaviors>
<is:MouseDragElementBehavior ConstrainToParentBounds="True" />
</i:Interaction.Behaviors>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The items are shown on the canvas but cannot be dragged or dropped. I create new items for the cardCollection in the viewmodel and the cardCollection is updated to the model via mvvm propertynotifychanged.

Caliburn.Micro message bubbling skipping a control

I've got a hierarchical collection and I lazy load the lowest level because of it's size.
The action I'm trying to activate is on the CollectionHolderManager but it seems that the bubbling skips that visual layer for some reason.
<ItemsControl DataContext="{Binding Path=CollectionHolderManager}"
ItemsSource="{Binding Path=CollectionTopLevel}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<telerik:RadToolBar cal:Bind.Model="{Binding}">
<TextBlock x:Name="Name" />
<ItemsControl ItemsSource="{Binding Path=CollectionMiddleLevel}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<telerik:RadDropDownButton cal:Bind.Model="{Binding}"
Content="{Binding Path=Name}"
cal:Message.Attach="[Event DropDownOpened] = [Action GetLowestLevel($dataContext)]">
<telerik:RadDropDownButton.DropDownContent>
<telerik:RadListBox SelectionMode="Multiple"
ItemsSource="{Binding Path=CollectionLowestLevel}">
<telerik:RadListBox.ItemTemplate>
<DataTemplate>
<!-- some template -->
</DataTemplate>
</telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>
</telerik:RadDropDownButton.DropDownContent>
</telerik:RadDropDownButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</telerik:RadToolBar>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
So if I have the action on the TopLevelCollection it get's called.
If I have it on the ViewModel that owns CollectionHolderManager it get's called, but not when it's on the CollectionHodlerManager itself. Why is it skipping over that?
Such a simple thing I can't believe I missed it.
<ItemsControl cal:Bind.Model="{Binding Path=CollectionHolderManager}"
ItemsSource="{Binding Path=CollectionTopLevel}">
Bind.Model instead of DataContext.

WPF: How to apply data template for items in ItemsControl if items are strings?

The ItemsControl defined below is filled with string[] WeekDays. The DataTemplate defined for ItemsControl.ItemTemplate doesn't work, i.e. the week day items are not filled with red background. How do I fix this? Thanks.
...
<ItemsControl
Grid.Row="1"
Margin="20,0,0,0"
ItemsSource="{Binding Path=WeekDays}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Background="Red" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
...
Note: string[] WeekDays is a dependency property of this control. I am not sure if this information might be relevant to finding the solution.
You need to bind the TextBox's Text property to something in order it to work. So, since the data context of the data template is the string itself the binding should be like this:
<DataTemplate>
<TextBlock Text="{Binding}" Background="Red" />
</DataTemplate>

Resources