Hi

 

I you worked with the WebBrowser control you probably met the following popup:

 

script error

 

I have started to use the WPF WebBrowser control in some of my applications but when I tried to disable the script errors I had a small problem the property WebBrowser.ScriptErrorsSuppressed  was not there, bummer…

 


Continue Reading...

Suppose you have several objects in your WPF application filled with similar Brushes which differ in brightness only. Like in this image:

red_rect

 

The nine rectangles use the same RadialGradienBrush but each rectangle is a little darker than previous. You can create these 9 different brushes in your favorite design tool (Expression Blend, etc.). But what if you need to change the base color later or you just need to make the brush user-configurable? Like in these samples:


Continue Reading...

Hi

 

When working with WPF I always found myself thinking how to handle Data formatting when a WPF control was bound to it. Let’s look at the following example of a window with a TextBlock that displays a DateTime:

   1: <Window x:Class="BindingFormat.Window1"

   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   4:     Title="Window1" Height="300" Width="300">

   5:     <Grid>

   6:         <TextBlock Text="{Binding}"></TextBlock>

   7:     </Grid>

   8: </Window>


Continue Reading...

This article was written by Alan Mendelevich

The Problem

Creating a shape with bullets on the joints of it’s segments sounds like a really trivial task at a first glance. Just plaster some bullets on top of the shape. And it is really something like this until you decide you want to have transparent outlined bullets or opaque bullets with transparent outline around them. Like the ones in this picture:

bulleted_path_samples

 


Continue Reading...

This article was written by Alan Mendelevich

 

Hi

 

Recently I’ve been working on a set of custom WPF controls.

There are numerous good books and articles about WPF in general and some basic information on custom control development but I have yet to find a good article (or book) with in-depth coverage of custom control development in general and design-time related issues in particular.

 


Continue Reading...

Hi

 

Here is a problem that one of my colleagues who is just starting to use WPF got himself into. He was working on an application that displays items using an ItemsControl and uses a DataTemplate. Inside the DataTemplate he used an Image. Here is the Xaml code:

 

   1: <Window.Resources>
   2:         <Image Source="Creek.jpg" x:Key="IMG"></Image>
   3:     </Window.Resources>
   4:     <Grid>
   5:         <ItemsControl ItemsSource="{Binding}">
   6:             <ItemsControl.ItemTemplate>
   7:                 <DataTemplate>
   8:                     <Border BorderThickness="2" BorderBrush="Black" 
   9:                             CornerRadius="3" MinHeight="10">
  10:                         <ContentControl Content="{StaticResource IMG}"/>
  11:                     </Border>
  12:                 </DataTemplate>
  13:             </ItemsControl.ItemTemplate>
  14:         </ItemsControl>
  15:     </Grid>

This is a much simpler example, but the principal is the same.

 

Can you see what was he doing wrong?


Continue Reading...

Hi

 

A while ago Shahar wrote an article about whether WPF Data Binding is Thread safe. Shahar’s findings were that Even if you change a property from a different thread the PropertyChanged event will be called on the UI Thread making Binding Thread Safe.

I have created a Window with 2 TextBlocks, one of them is binded to a Dependency Property and the other is binded to a regular property:

The Window:

   1: <StackPanel>
   2:     <TextBlock Text="{Binding DpTxt}" Width="100" Margin="5"></TextBlock>
   3:     <TextBlock Text="{Binding Txt}" Width="100" Margin="5"></TextBlock>
   4:     <Button Content="Change Text" Margin="5" Click="Button_Click"></Button>
   5: </StackPanel>


Continue Reading...

Hi

 

Where do you locate your convertors? do you put them in the Window.Resources section? or in the UserControl they are being used for? Neither of these options is good. You should put it in the App.Xaml file and here is why:

Lets look at the following example:

Here is our Window:

   1: <Window x:Class="ConvertorLocation.Window1"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:         xmlns:my="clr-namespace:ConvertorLocation"
   5:     Title="Window1" Height="300" Width="300">
   6:     <Grid>
   7:         <ItemsControl ItemsSource="{Binding}">
   8:             <ItemsControl.ItemTemplate>
   9:                 <DataTemplate>
  10:                     <my:UserControl1></my:UserControl1>
  11:                 </DataTemplate>
  12:             </ItemsControl.ItemTemplate>
  13:         </ItemsControl>
  14:     </Grid>    
  15: </Window>

Continue Reading...

Hi

 

While working on a complex UI application in WPF I noticed that because I was using DataTemplates both the Xaml and the Code Behind got very messy, that is because if you need to implement some events in the code behind you basically “mix” code from the template and code from the Window, plus you cannot access the elements in the template from the code behind.

Let’s look at the following example:


Continue Reading...

Hi

 

Yesterday I was trying to create a control with a partially transparent background,. I am writing this because what I thought was so straight forward, was not.

Here is a simple example:

   1: <Grid>
   2:    <Button Height="23" Margin="94,103,109,0" Name="button1" 
   3:            VerticalAlignment="Top">Button</Button>
   4:    <Border Margin="57,61,21,101" Name="border1" 
   5:            Background="blue" />
   6: </Grid>

When we run this example we will get the following:


Continue Reading...