.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

When binding Style on a UserControl to Application.Resource a consumer of the usercontrol fails to r

Posted By:      Posted Date: October 26, 2010    Points: 0   Category :WPF

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:
        <Style x:Key="GridHeaderFade" TargetType="{x:Type Grid}">
            <Setter Property="Grid.Background">
                    <LinearGradientBrush ColorInterpolationMode="SRgbLinearInterpolation" >
                        <GradientStop Color="#FFFFFFFF" Offset=".3"/>
                        <GradientStop Color="#B0a0a0a0" Offset=".85"/>
                        <GradientStop Color="#FFFFFFFF" Offset=".99"/>
Then in my address control I use:
<Grid Grid.Row="0" Style="{StaticResource GridHeaderFade}" >
            <Label HorizontalAlignment="Left" Margin="0,-7,0,0"  FontSize="

View Complete Post

More Related Resource Links

Using an Application Resource in Nested UserControl

Hello This problem has been niggling me for months and I just can't seem to get to the bottom of it. I have a UserControl, let's call it 'UC_List', and the ListBox in it uses a Style which I have declared in my Application.xaml file. When working with UC_List.xaml everything seems fine. I then place 'UC_List' into a UserControl, let's call it 'UC_Summary'. I have declared the namespace at the top of UC_Summary.xaml. The xaml code in UC_Summary now has an Error: Could not create an instance of type 'UC_Summary'. Now I cannot see anything in the Design window, only a warning saying 'Problem Loading, the document contains errors that must be fixed...' However when I run the application everything works fine! After a lot of trial and error I found that the cause of the problem seems to be the Style referenced in the Application.xaml. If I declare the Style in UserControl.Resources at the top of UC_List the error goes away and the graphics in UC_Summary return. I've so far duplicated my Styles into individual UserControls to work around the problem but this could easily lead to inconsistancies. If anyone can suggest anything I would be really pleased to try it. Thank you. Regards Chris

Binding UserControl property to Page property

So what I'm trying to accomplish is this <uc3:UserControl ID="UserControl 1" runat="server" ClockNumber='<%=ClockNumber %>' Month='<%#Month %>' Year='<%#Year %>' />The user control has public properties named accordingly and the page has protected properties accordingly which I've verified have the desired values.For some reason the values are always empty strings or 0s in the usercontrol, no matter what the page property is.Thanks for any suggestions

XAML UserControl ItemTemplate Binding does not work

Hi there!

I have defined a UserControl to implement a Checkboxed Combobox following the post of justguy:

<UserControl x:Class="KittyUserControlLibrary.ComboWithCheckboxes"


        ItemsSource="{Binding ElementName=UserControl, Path=ItemsSource}"
        DataContext="{Binding ElementName=UserControl, Path=DataContext}"

                <CheckBox Content="{Binding Title}"
                          IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
                          Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"

            <ControlTemplate TargetType="ComboBox">

UserControl in DataTemplate for a GridViewColumn data binding


Hey guys,

I have a UserControl with a TextBox in it (in my app, it's a little more than a text box - but for reproducing I used the textbox). This UC is put inside a DataTemplate for a GridViewColumn cell template. Below is  the UC.

<UserControl x:Class="XXX.TestUC"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <span style="font-family:Verdana,Arial,Helvetica,sans-serif; white-space:normal; color:#8b008b">xmlns:<span style=

binding usercontrol elements properties


I am desperatly trying to understand bindings in WPF, I would like to understand how I can bind the elements of 2 Usercontrols to each other, so that if I change the value of the slider the circle strokethickness changes and if I change the circle strokethickness the slider changes. I have some code that hopefully explains what I want to understand better. TIA Mike

<Window x:Class="WpfDependencyTest.MainWindow"






  Title="MainWindow" Height="350" Width="525">


  <local:UcCircleText ></local:UcCircleText>

  <StackPanel Height="Auto" HorizontalAlignment="Right" x:Name="stackPanel1" VerticalAlignment="Bottom" Width="Auto" Background="Aqua">

   <local:UcSlider Height="150" Width="150"></local:UcSlider>



Problem with UserControl Style




i work with .net 3.5 and vs 2008 and have the following problem:

i build a UserControl for serialnumber-input like that: A12F - 35GH - LKJM -34JM

the control contains 4 textboxes and 3 textblock between the textboxes, for showing a seprater-char

the control validate each of the 4 textboxes. that works fine but i have a problem with the Style if a validation-error occurs.

it's shows the errorstyle around each TextBox but i want to get it around the whole UserControl.

if i change the TargetType of the Style to my UserControl-Type i get an error.

so, how do i get this Style around the whole UserControl or do i need to create a Custom Control ?


<Style x:Key="SerialNumberTextBoxStyle" TargetType="TextBox">

UserControl Visibility binding Issue.

<UserControl x:Class="Org.Intermountain.ICM.Views.Authentication.LoginFormView"
             d:DesignHeight="636" d:DesignWidth="946"
             IsEnabled="{Binding IsControlEnabled}" 

how to make a css style background image be linked to an image in the resource file


hey guy, i need help in a very troubling matter. I want to make a textbox with a specific style, within this style a set of images as background parts, how can i attach these images to the custom control as whenever i take the .dll file and add it to the toolbar the images do not appear. So i tried to make them as resource files and their property as embedded in .resx file, so how to make the css style background image url to be linked to any of those image.

thanks in advance

UserControl like asp:Panel


Is it possible to write own User Control with functionality like asp:Panel?

SharePoint 2010: Application Lifecycle Management (ALM) Resource Center

Are you looking for information about BCS? BCS enables users to read and write data from external systems-through web services, databases, and .NET assemblies.

UserControl, CustomControl Design Time Support errors IOC, Dependency Injection, MVP

  Hi, is there a way to completely disable design time support for CustomControl, and UserControl ? I have about 30 UserControls and 10 CustomControls in my WinForms app, which contains some Dependency Injections and IOC stuff in constructors and Load handlers. I have lots of large UserControls containing smaller UserControls (CompositeView). All my UI code is pretty dynamic and the only thing i need to do at design time is to drag&drop containers in other containers (UserControls). And now i have a hard time doing this, because i have to wrap all constructors and Load Handlers in CurrentProccess!="devenv"... and when I'm Implementing some new View interface (which consist lots of properties) in UserControl all those properties by default throw NotImplementedException and i don't always need to implement them immediately but still i need to be able to run this code for testing. Besides, then i have to clean up designer generated class because it adds unnecessary null value property initializations, and then it way add some other ____ code, and so on.... Imagine UserControl with 10-15 nested UserControls, and then i try to open it in Form Designer and get ObjectReference NULL exception (for IOC) or some NotSupported NotImplemented exceptions (for properties) without adequate CallStack available! There is a CallStack but there is no trace in it to my Code (

How to load a usercontrol xaml at runtime ???????

Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

Property of a base UserControl it's not handled correctly

Hello,I have a class that is a base class for my server controls. Inside this class I have a property that can take values from an enumeration.public enum PanelModeEnum { Add = 1, Edit = 2, ReadOnly = 3 } public class BaseControl : System.Web.UI.UserControl { #region Event Handling Management #endregion public PanelModeEnum PanelMode { get; set; } public virtual void ChangePanelMode(PanelModeEnum newMode) { this.PanelMode = newMode; } } I have then several user controls that inherits from this BaseControl and that I add into aspx pages declaratively<gsl:PhoneNumberUC ID="ucPhoneDetail" runat="server" PhoneNumberType="Home" />I would like to show one the derived BaseControl classes inside a ModalPopupExtender using server-side code. Before doing this I call the ChangePanelMode with a value from the PanelModeEnumucPhoneDetail.PhoneNumberType = ptype; ucPhoneDetail.ChangePanelMode(PanelModeEnum.Add); this.mpePopupPhone.Show(); But when, inside the inherited user control I check for the PanelMode property likeif (this.PanelMode == PanelModeEnum.Add) { ... } the value of this.PanelMode is always equal to zero. Why?Kindly regards

Detect Deactivation of Usercontrol

Hi All, I have added a popup type usercontrol to a form which I call like this: MyUserControl = New AdvancedControl MyUserControl.StartPosition = FormStartPosition.Manual MyUserControl.TopLevel = False MyUserControl.Location = Me.Parent.PointToScreen(New Point(Me.Left, Me.Bottom)) ParentForm.Controls.Add(MyUserControl) MyUserControl.Show()  How can I detect when a user clicks somewhere other than the usercontrol and then dispose of the usercontrol.  The lost focus and deactivate events dont seem to fire. Thanks

Binding byte[] to image control in navigation application leaks

Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

usercontrol used in datagridviewcell

Dear Programmers, Im trying to create a user control above to be used inside a datagridviewcell this user control, has a button and a textbox. Used for lookup it loads a form the user choose the row and the record id or primary key is loaded to the uercontrol textbox. the variables are now private static, but when i have 2 usercontrols in the same datagridview, the values are the same. And when i change the properties variable from static to nonstatic public variables. the variable values are not seen and the control dont work. I will upload the classes below. I appreciate your help.<pre lang="x-c#"> namespace x { public class DataGridViewButtonTextBoxColumn : DataGridViewColumn { public DataGridViewButtonTextBoxColumn() : base(new DataGridViewButtonTextBoxCell()) { //base.DefaultHeaderCellType = typeof(DataGridViewTextBoxCell); //base.SortMode = DataGridViewColumnSortMode.Programmatic; } public override object Clone() { DataGridViewButtonTextBoxColumn Column = (DataGridViewButtonTextBoxColumn)base.Clone(); Column.DBName = this.DBName; Column.ComboLup = this.ComboLup; Column.PrimaryKeyField = this.PrimaryKeyField; Column.PrimaryKeyField2 = this.PrimaryKeyField2; return Column; } public override DataGridViewCell CellTemplate { get { return
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend