Hi,
I have a WPF application that has a UserControl called 'Address' which sets up a simple form with a grid some labels and some data input controls (TextBoxes..etc.)
I made a little style resource to add a gradient to a grid row background for my headings like this:
<Application.Resources>
<Style x:Key="GridHeaderFade" TargetType="{x:Type Grid}">
<Setter Property="Grid.Background">
<Setter.Value>
<LinearGradientBrush ColorInterpolationMode="SRgbLinearInterpolation" >
<GradientStop Color="#FFFFFFFF" Offset=".3"/>
<GradientStop Color="#B0a0a0a0" Offset=".85"/>
<GradientStop Color="#FFFFFFFF" Offset=".99"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
Then in my address control I use:
<Grid Grid.Row="0" Style="{StaticResource GridHeaderFade}" >
<Label HorizontalAlignment="Left" Margin="0,-7,0,0" FontSize="16" FontWeight="Bold" Name="lblAddressName" Content="{Binding AddressName}" />
</Grid>
While I am editing the Address.xaml UserControl the gradient shows in my row 0. The solution complies no problem. In fact it works when you run the WPF App.
Now, I have another UserControl named 'Contact' this user control consumes the Address control twice. One is named the Billing Address and one is named the Mailing Address. This control is setup like this:
<UserControl x:Class="Administrator.Controls.Contact"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Administrator.Controls"
Height="500" Width="600">
<Grid Height="800" Width="600">
<ScrollViewer Margin="0,0,0,67" Name="scrollViewer1">
<StackPanel>
<controls:Address x:Name="addrBilling" HorizontalAlignment="Left" AddressName="Billing Address" Margin="0,0,0,0" Width="581"></controls:Address>
<controls:Address x:Name="addrHome" HorizontalAlignment="Left" AddressName="Home Address" Margin="0,0,0,0" Width="581"></controls:Address>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
Note: My Address.xaml and Contact.Xaml are in the same WPF Appliction project in a folder named 'Controls' and thus the namespace of the controls are 'Administrator.Controls', explaining the xmlns at the top of the code.
So when I add these Address controls to the Contact User Control, the designer complains that there is a problem with the XAML. The blue squigly XAML error is 'Could not create instance of 'Address''. The project works it simply will not let me design the Contact.xaml.
If I delete theStyle="{StaticResource GridHeaderFade}" from the Row="0" line of my Address.xaml file the designer will show both Address controls correctly on the designer but of course no fade in my grid row.
What I am trying to accomplish:
I would like to be able to 'skin' or 'style' my controls at a high level and allow all my sub-controls in the project to reuse the same style elements. This is why I defined them in the Application.Resources section. If there is a better way for this please explain.
Thanks for your help,
David Sandor
Mark the best replies as answers!