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

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

MarkupExtension only initialized once in DataTemplate in .Net 4

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :.NET Framework


I create a LocalizationProvider markup extension to support multi-language in my application. In .Net 3.5, everything works fine, but after i upgrade to .Net 4, sometimes the LocalizationProvider fails to work. After debug i found that the LocalizationProvider contained in a data template only be constructed once in .Net4, but in .Net 3.5 it will be constructed many times (every time the data template is applied). And that's the problem, i need a individual LocalizationProvider for each item the template is applied.

Same codes: (The LocaliztionItem (derived from frameworkelement) in the xaml also initialized once only. And I found a workaround: If  i change the LocalizationItem in xaml like this <localization:LocalizationItem Tag="{StaticResource brush}" ...  the LocalizationProvider will be constructed many times again. )

<Window x:Class="LocalizationTestApp.MainWindow"

View Complete Post

More Related Resource Links

Again, Getting control inside datatemplate from code behind

HI, All: This problem comes back to bite me again. I had a similar problem before but I changed the customer control to user control and define the click event in the xaml. But this time I have to stick with the customer control. I searched the internet and there are a lot of examples but in my situation, I still got null object. I have a CUSTOMER control which derives from treeview. The hierachicalDataTemplate for the treeview is following:     <HierarchicalDataTemplate         x:Key="CheckBoxItemTemplate"         ItemsSource="{Binding SubFolder}"         >         <StackPanel Orientation="Horizontal">             <CheckBox             x:Name="PART_CheckBox"             Focusable="False"             IsChecked="{Binding IsSelected}"             VerticalAlignment="Center"                 &nbs

Controls within Base Control are Not initialized

I have an ASP.net control that contains a grid (protected member variable). Grid is populated from a function in the control. I have derived a new user control from this control without any control in it. I added additional functionality to populate grid and called base class function to do further operation on the grid.When I run my code, I get the null reference exception on grid object in the base control.Any idea why this might happen? Am I missing something in control inheritance? at what point do inner controls get created? 

UI Automation with DataTemplate

Hello All! I'm trying to test a WPF application that uses lots of DataTemplates. I'm trying to test the UI aspect of the app by the means of UI Automation. Unfortunately, when I try to find element of interest, I always fail. I have tried using UISpy (which, if I'm not mistaken, shows what UI Automation sees) and still no luck. UISpy doesn't show anything inside of a template. I was wondering if anyone has faced this issue before and how can I get passed this "wall'. Thanks for your help. dimaj

Default DataTemplate

Hi, I'm templating an object with some data templates based on DataType... is there a way to apply another "default" DataTemplate (which I want to define in XAML) when I bind to an object that has not a datatemplate with its datatype?

SQL Server Reporting Services 2008 R2 - The configuration system has already been initialized

After correcting issues related to .NET 4.0, I am now encountering the error below. It occurs when I attempt to access one of the two web sites. I've been tracking my install/config progress here: http://serverfault.com/questions/178353/what-would-cause-a-500-internal-server-error-when-accessing-the-report-manager-ur   Error Log: appdomainmanager!DefaultDomain!ae8!09/07/2010-14:47:12:: i INFO: Appdomain:13 ReportServer_11-11-129283588326974843 started. appdomainmanager!DefaultDomain!ae8!09/07/2010-14:47:12:: e ERROR: AppDomain ReportServer_11 failed to start. Error: The configuration system has already been initialized. library!DefaultDomain!ae8!09/07/2010-14:47:12:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: Failed to create HTTP Runtime, Microsoft.ReportingServices.Diagnostics.Utilities.ReportServerHttpRuntimeInternalException: An internal or system error occurred in the HTTP Runtime object for application domain ReportServer_11.  ---> System.InvalidOperationException: The configuration system has already been initialized.    at System.Configuration.ConfigurationManager.SetConfigurationSystem(IInternalConfigSystem configSystem, Boolean initComplete)    at System.Web.Configuration.HttpConfigurationSystem.EnsureInit(IConfigMapPath configMapPath, Boolean listenToFileChange

Set DataTemplate from resource programmatically

Hi,   I am trying to style one of my columns in my ListView. I have created a DataTemplate in one of my resource files: <DataTemplate x:Key="MyTemplate"> <Border BorderBrush="Brown" BorderThickness="2" CornerRadius="5"> <Border.Background> <LinearGradientBrush> <GradientStop Offset="0" Color="Wheat"/> <GradientStop Offset="1" Color="LightCoral"/> </LinearGradientBrush> </Border.Background> <TextBlock Foreground="Blue" FontWeight="Bold" Margin="5" Text="{Binding Id}" Width="Auto"/> </Border> </DataTemplate>   In my XAML I have added this resource file. I use other stuff from this file so that part works fine. <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="MyTemplates.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources>   However, I don't create the columns in XAML, instead they are created in C#: ((GridViewColumn)c.Value).CellTemplate = (DataTemplate)FindResource("MyTemplate");   Now, when I run this I get an exception saying it can find the resource "

Cannot create Team Foundation Server project: report server not initialized.

(TFS 2008, SQL 2005, SharePoint 2007) OK.  So the Report Server isn't initialized.  I get that. I open Report Configuration and Initialization is grayed out.  I look at SharePoint Integration and it tells me to create a database that can be integrated with SharePoint.  No problem. Go to Database Connection and try to Upgrade - can't do that unless I create a new database.  Select Change...it tells me it would be happy to change out of native mode but will have to create a new database....great, since that's what I want to do anyway.  Yes.  Using Current User credentials (signed on as domain administrator) I enter a db name check the sharepoint integration box and hit OK.....I have a new database in SharePoint integrated mode.  SharePoint Integration is green BUT Initialization is still grayed out and I still can't create a new TFS project. What do I do now????

DataTemplate binding based on object property


I have a collection of objects that I'm giving visual representation in my UI through DataTemplates. Each object has a string property "field". 

Is it possible for my UI to exclude specific objects in my collection from being shown based on the "field" property if it contains a string "foo"? 



Error MC3045 while using MarkupExtension in XAML



I have created a xaml extension, that inherits MarkupExtension. I use this in my xaml:

In this syntax, it doesn't work :

<TextBox Text="{local:MOP_ValeurBinding {x:Type mopval:MOP_String}, Path=Data.DGC.Nom, MyConverter={StaticResource teststringconverter}}" />

I get error : error MC3045: Unknown property 'MyConverter' for type 'MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension' encountered while parsing a Markup Extension

In this syntax, it's works fine :

Connect DataTemplate from resource , to existing class.

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


<src:CatList x:Key="cat"/>


first Thanks.

Where <sr

DataTemplate trigger to set templated parent property


Hy everybody,I am struggling with a problem.I basically want to provide a data template for my data model and when a trigger on the view happens,I want to change a property in my data model.I cannot figure out how to tell the Setter that it needs to change a property of the templated parent. Here is how it looks now:

My data model for a "Line" looks like this:


public class LineModel : DependencyObject
    public ushort Value
        return (ushort)base.GetValue(ValueProperty);
        base.SetValue(ValueProperty, value);
    public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(ushort), typeof(LineModel));


Creating Datatemplate via codebind for a CategoryEditor



I am trying to implement a CategoryEditor programmatically. Normaly you use a XAML defined DataTemplate but in my case I have to do it with code. In XAML there is no problem. But how du I realize the datatemplate bindings. For example the following code snippet 

  <TextBox Text="{Binding [MyProperty].PropertyValue.Value}" Grid.Column="1"/>

Here is my suggestion

DataTemplate dt = new DataTemplate();
FrameworkElementFactory textBox = new Framew

ChangePropertyAction to modify Visibility not working in ListBoxItem DataTemplate.

I am trying to change the visibility of a control in a ListBoxItem template (based on it beeing selected in the parent listbox) through a ChangePropertyAction but the code below does not work. I tried fiddling around with setting the TargetName on the trigger or setting the default visibility of the control through a style. I debugged the Binding through a DebugConvert and checked that the IsSelected is correctly set to true but it still does not work. Can anybody explain to me why this is not working and how I can fix this?

VS 2010 crash when add ContentPresenter to a DataTemplate


As explained in the subject I'm defining a DataTemplate for a ContentControl (or Button in the same way). When I add the ContentPresenter to the data template the IDE crashes with any exception message.


Do anybody know the cause or have the same problem?



binding to properties inside a datatemplate


Hi all


Im creating a user control which will act like a border.  I will be able to specify via properties each side of the borders thickness and color.  I am using a DataTemplate for this because I want to be able to specify where I want the content to go inside the user control.


My problem is I can’t seem to get the properties iv created in code (get;set) to change the thickness or color or the borders iv created in the xaml file.  Iv tried binding to them in the xaml file however they are not getting called.



Getting IXamlNamespaceResolver in MarkupExtension.ProvideValue from the designer.


I'm creating a markup extension in Visual Studio 2010 that will be used for localization. As part of this, I want to be able to pass an xml namespace prefix from the xaml and have the extension translate it to the full namespace string. This is possible using IXamlNamespaceResolver, however this only works for me at runtime and not from the VS2010 designer, which I need so that I can preview how the UI will look for different locations. I have a workaround where I set the namespace as a string and pass that instead of using xmlns, but I'd like to avoid doing that.

Here an example of what I want in the MarkupExtension.ProvideValue method:

public override object ProvideValue(

ExecuteReader problem in web form: Connection-property not initialized


I changed my data source from an access-db to a sql-server, now i still have to fix some problems Undecided

When I want to load a value from a sql-database into my web form (to display a default value), I get an ExecuteReader error ("Connection-property not initialized").

I dont know where to set the connection property in my code.

Dim con As New System.Data.SqlClient.SqlConnection()
Dim myCommand As New System.Data.SqlClient.SqlCommand
Dim SqlCon As String = "Data Source=blablabla\SQLEXPRESS;Initial Catalog=Bill;Persist Security Info=True;User ID=xxx;Password=password"
con.ConnectionString = SqlCon
Dim reader As System.Data.SqlClient.SqlDataReader = myCommand.ExecuteReader() 

The error occurs in the last line. Do I have to set the connection property in the SqlCon string?

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