The calling thread must be STA, because many UI components require this
Try to invoke your code from the dispatcher: Application.Current.Dispatcher.Invoke((Action)delegate{ // your code });
Try to invoke your code from the dispatcher: Application.Current.Dispatcher.Invoke((Action)delegate{ // your code });
I needed to add the mc:Ignorable=”d” attribute to the Window tag. Essentially I learned something new. The d: namespace prefix that Expression Blend/Visual Studio designer acknowledges is actually ignored/”commented out” by the real compiler/xaml parser! <Window … xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ mc:Ignorable=”d” xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″ … /> The following was taken from Nathan, Adam (2010-06-04). WPF 4 Unleashed (Kindle Locations … Read more
Typically a control is rendered for its own sake, and doesn’t reflect underlying data. For example, a Button wouldn’t be bound to a business object – it’s there purely so it can be clicked on. A ContentControl or ListBox, however, generally appear so that they can present data for the user. A DataTemplate, therefore, is … Read more
You could try something like this: …Binding=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.AllowItemCommand}” …
It really depends on what you are trying to achieve, and how much infrastructure you want in place already, plus the ease with which you can find samples that help you out. I’m going to declare an interest here, because I’ve been actively involved in at least one MVVM framework, and I’ve had input into … Read more
Set the window’s property SizeToContent=”WidthAndHeight”. This should help.
You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat=”{}{0} + {1}”> <Binding Path=”Name” /> <Binding Path=”ID” /> </MultiBinding> </TextBlock.Text> </TextBlock> Giving Name a value of Foo and ID a value of 1, your output in the TextBlock would then be Foo + 1. Note: This … Read more
A Textblock itself can’t do vertical alignment The best way to do this that I’ve found is to put the textblock inside a border, so the border does the alignment for you. <Border BorderBrush=”{x:Null}” Height=”50″> <TextBlock TextWrapping=”Wrap” Text=”Some Text” VerticalAlignment=”Center”/> </Border> Note: This is functionally equivalent to using a grid, it just depends how you … Read more
Use a TextBox with these settings instead to make it read only and to look like a TextBlock control. <TextBox Background=”Transparent” BorderThickness=”0″ Text=”{Binding Text, Mode=OneWay}” IsReadOnly=”True” TextWrapping=”Wrap” />
How about add this to your xaml: <Separator/>