Access ResourceDictionary items programmatically

Got it solved. I needed to: load my resource dictionary merge it with the application’s resources load my control template from the application resource As part of loading the resource dictionary, i also had to register the pack URI scheme. I then had to deal with some crazy COM based exceptions due to slight errors … Read more

Invalid cross-thread access issue

In order to update a DependencyProperty in a ViewModel, use the same dispatcher you would use to access any other UIElement: System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {…}); Also, BitmapImages have to be instantiated on the UI thread. This is because it uses DependencyProperties, which can only be used on the UI thread. I have tried instantiating BitmapImages on … Read more

Access codebehind variable in XAML

There are a few ways to do this. Add your variable as a resource from codebehind: myWindow.Resources.Add(“myResourceKey”, myVariable); Then you can access it from XAML: <TextBlock Text=”{StaticResource myResourceKey}”/> If you have to add it after the XAML gets parsed, you can use a DynamicResource above instead of StaticResource. Make the variable a property of something … Read more

Bind Collection to StackPanel

Alright I have figured it out… Using an ItemsControl solved the problem… <ItemsControl x:Name=”tStack” ItemsSource=”{Binding Items}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation=”Horizontal”/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Content=”{Binding ItemName}”/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

MVVM light – how to access property in other view model

You could use the Messenger to do this: Send the user in the UserViewModel: Messenger.Send<User>(userInstance); would just send the user to anyone interested. And register a recipient in your CardViewModel: Messenger.Register<User>(this, delegate(User curUser){_curUser = curUser;}); or you can also send a request from your CardViewModel for shouting the user: Messenger.Send<String, UserViewModel>(“Gimme user”); And react on … Read more