.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

How to use 2 xaml files with one code behind

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

Hi all,

I am developing a SW that can automatically detect the render ability of current machine then decide what GUI file is loaded. At this time, I have to create these files:

1. HighResGUI.xaml + HighResGUI.xaml.cs

2. LowResGUI.xaml + LowResGUI.xaml.cs

Both HighResGUI.xaml.cs and LowResGUI.xaml.cs are the same, only the xaml has different styles (due to the render capability of the current machine). This can solve my problem, at this time. However, when I want to modify one xaml.cs code, I have to do it twice for both High and Low.

So my question is, how can I combine these two different interface (HighResGUI.xaml+ LowResGUI.xaml) and use only one code behind, for example common.xaml.cs?



View Complete Post

More Related Resource Links

Code Name WinFS: Revolutionary File Storage System Lets Users Search and Manage Files Based on Conte


One of the monumental problems organizations face today is aggregating information that's stored in disparate formats. Knowledge workers have long wanted to be able to search for content independent of format. The next version of the Windows operating system, code-named "Longhorn," boasts a new storage subsystem that makes that task easier. That subsystem, code-named "WinFS," allows the user to perform searches based on the metadata of the stored item, regardless of what type of file it is or which application created it. This article covers the basic architecture of WinFS and explains how to use the WinFS managed API.

Richard Grimes

MSDN Magazine January 2004

How to set Panel.Zindex value though XAML code if any of the Grid/UserControl children having the fo

Hi, I have a Grid with 10 buttons. If any of these buttons has focus then I want to set the Panel.Zindex = 999 for the Grid. How to do this in XAML code?Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

External Code Assemblies, Report Subscriptions, and configuration files

I've got a report that relies on a very small external assembly for data for one of its fields.  That assembly, in turn, relies on some values from System.Configuration for portions of its work. I have the configuration keys and values running fine in the web interface, set up in web.config, but when users set up subscriptions for the report it runs fine but doesn't retrieve the configuration values from web.config (as expected) nor does it retrieve them from rsreportserver.config, where I have tried them in the root of the config file as <add key=... /> entries and also by wrapping them inside an <appSettings /> node.  I have also tried them in an appropriately-name config file in the bin directory.  In all cases the report is fine except the field that relies on the external assembly, where I recieve an error indicating that there's missing information (the config vals are used in a String.Format() call): Value cannot be null. Parameter name: format at System.String.Format(IFormatProvider provider, String format, Object[] args) at ExternalDBFunctions.ExternalSelectors.GetNotificationStati(String NotificationID) mscorlib When I remove the config values from the web.config, the web interface shows exactly the same error. Where should these configuration values go?

Data from text files, What's wrong with my code?

Hi all, I have uploaded some tab-delimited .txt files on my web site (actually run on my computer, ie localhost, for now), and now I try to retrieve the data from those files. I do this by calling a vb file containg the sub below. Everything works great, except that the sub won't recognise unicode characters. I can split the resulting string using vbnewline and vbtab, but already in the sub in question, the string doesn't understand the Swedish letters åäö, apostrophes and more. Any help would be greatly appreciated! /Pettrer       Shared Function getTextfile(ByVal FullPath As String, Optional ByRef ErrInfo As String = "") As String Dim strContents As String = "" Dim objReader As StreamReader Try objReader =New StreamReader(FullPath) 'UTF8Encoding? strContents = objReader.ReadToEnd() objReader.Close() ErrInfo = Ex.MessageCatch Ex As Exception End Try Return strContents End Function  

How to set MaxLength on DataGridTextColumn in C# code, not XAML

Hi. Im creating DataGridTextColumns dynamicly in C# but I need to limit the column input length. Is there a way to do it? I tried to use textbox style because textbox has MaxLength property but DataGridTextColumn does not allow to use styles with textbox targettype :( Any ideas please?  

Uninstall error -- The timestamp marker on log files has been set. Error code 0x84B20001

I need to uninstall from the command line for an application we are writing SQL Express 2008.  I am using the following command to debug an error message,   setup100.exe /ACTION=UNINSTALL /INSTANCENAME=SUNKIST /FEATURES=SQL   and I keep on getting an error message:   SQL Server Setup Failure The timestamp marker on log files has not been set.  The timestamp must be set set prior to it being used for the first time.  Error code 0x84B20001   the log files seems to have problems in the following area,    Running Action: SaveFeatureStateAction2008-10-01 15:00:51 Slp: Completed Action: SaveFeatureStateAction, returned True2008-10-01 15:00:51 Slp: Completed Action: ExecuteUninstallCalculateWorkflow, returned True2008-10-01 15:00:51 Slp: ----------------------------------------------------------------------2008-10-01 15:00:51 Slp: Running Action: ProduceStatusLogs2008-10-01 15:00:51 Slp: Error: Action "ProduceStatusLogs" threw an exception during execution.2008-10-01 15:00:51 Slp: Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException: The timestamp marker on log files has not been set. The timestamp must be set prior to it being used for the first time. ---> Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException: The timestamp marker on log files has not been set. The timestamp must be set prior to it being used for the first time. --->

Input parameters from Workflow No-Code Or Xaml Only

I have many activities and a customized workflow Only Xaml and I can not pass a value to a property of a custom activity, following the example of Workflow1.xoml   <pre lang="x-xml"><SequentialWorkflowActivity x:Name="Workflow1" xmlns:ns0="clr-namespace:CustomActivities;Assembly=CustomActivities, Version=, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"> <ns0:ReadLineActivity x:Name="readLineActivity1" InputText="" /> <ns0:WriteLineActivity x:Name="writeLineActivity1" OutputText="{ActivityBind readLineActivity1,Path=InputText}" /> </SequentialWorkflowActivity> based on this workflow I pass a value for the property InputText activity readLineActivity1   Thanks a lot!

write server side code in External JS files

Salam To All,for my JS code, some times i need to organize my code, so i prefer to put some of javascript functions in external js files and  include it in my page as well.but i am face a problem if i need to write some .Net code especially to Get the Client ID for any of .net controls.so do you have a way to write the following code in External JS file?('#<%= this.ddlMake.ClientID %>').change(function(

Textrange.Load not loading Xaml code into a FlowDocument


I'm trying to convert text with Xaml tags into a FlowDocument.  I've done this before and it worked fine (as far as I can recall - that was about a year ago.)  Now I can't get this to work:

private Span FormatString(String _textToFormat)
    FlowDocument _formattedDocument;
    Span _formattedText;

    _myString = "<FlowDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>This is some <Run FontWeight=\"bold\">bold</Run> text.</Paragraph></FlowDocument>";

    _formattedDocument = new FlowDocument();
    _formattedText = new Span();

    TextRange textRange = new TextRange(_formattedDocument.ContentStart, _formattedDocument.ContentEnd);

    MemoryStream msDocument = new MemoryStream((new ASCIIEncoding()).GetBytes(_myString));
    if (textRange.CanLoad(DataFormats.Xaml))
        textRange.Load(msDocument, DataFormats.Xaml);

// rest of function trimmed - the problem is above

Things work fine up to and including the creation of the MemoryStream (inspection with the debugger shows that the bytes are in there.)  "textRange.CanLoad" also resolves to true, but textRange.Load(msDocument, DataFormats.Xaml) doesn't seem to do anything - after that, a look at "textRa

VS 2010 unable to edit or display xaml files.


I am having a problem using the editor for xaml files in Visual Studio 2010.

I have used Visual Studio 2005 and 2008 for many years.  Over the last year or more I have been constructing and maintaining a Silverlight application, editing both the xaml code and using the design mode.  I am quite familiar with it and it worked fine.

However we recently installed several copies of Visual Studio 2010 as trial versions and since it seemed OK we converted to the full version.  However now I am having trouble viewing xaml files in the editor, in either the design mode or as text. 

Double clicking on a xaml file in the Solution Explorer, which should start the xaml editor, now does very little, leaving the main screen blank. The file seems to be open since it is listed in the list of open files in the 'Windows' drop down menu.  If I ask it to reload the file it says it is already open and do I want to close it before continuing.  But it is not accessible or visible.

Right clicking on a xaml file and selecting 'Open with..' shows the 'Automatic Editor Selector' is selected as default.  If I select 'Text Editor' I can at least see and edit the xaml code.  But I can not see the design mode.  If I select 'Windows Presentation Foundation Designer with encoding' from the 'Op

Issue with designer files not updating -- and therefore cannot code



I have a problem in which some nested controls on a page are not updated in the designer file. I have deleted the designer file, selected Convert to Web Application, but still the controls are missing.

I know there is a supposed fix at http://blogs.msdn.com/b/webdevtools/archive/2010/03/05/hotfix-for-issue-with-auto-generated-designer-files-not-adding-controls.aspx

Unfortunately the patch won't install and I still have the issue.

Any thoughts? I am running VS 2010 Version 10.0.30319.1 RTMRel.



Extending Page class in XAML and code-behind


I have several XAML "Page"s for which I would like to pull the facets that are in common together into a Page class extension I am calling ACPage. I must be missing some essential piece of knowledge, although I think I am pretty close. Can someone tell me what I am missing? I am learning C#, XAML, .NET, etc. all simultaneously.

I get the following warning:
Warning 1 'Al_Cr.PageWelcome.InitializeComponent()' hides inherited member 'Al_Cr.ACPage.InitializeComponent()'. Use the new keyword if hiding was intended. D:\Projects\Al Cr\Al Cr\Al Cr\obj\x86\Release\PageWelcome.g.cs 50 21 Al Cr

and this error:
Error 2 'Al_Cr.ACPage' cannot be the root of a XAML file because it was defined using XAML. Line 1 Position 15. D:\Projects\Al Cr\Al Cr\Al Cr\PageWelcome.xaml 1 15 Al Cr

The warning points to the auto-generated PageWelcome.InitializeComponent() function definition. The error points to the end of the bolded text, below.

My ACPage.xaml & ACPage.xaml.cs is defined thusly:

<Page x:Class="Al_Cr.ACPage"

Setup file(*.msi) also includes .aspx.cs (source code) files also


My project is recently migrated from 2008 to 2010

actualy we developed project in VS 2005 in that we created setup file but when we migrated to vs2008 setup file giving problem to us.

now when we make setup file it is including .aspx.cs files also but this if we publish our project it wont including source code.

why setup file including .aspx.cs files is there any way to change.

plz replay ASAP

Binding an ObservableCollection via XAML without code behind



I think I am missing something basic here.. But could someone show me what I am doing incorrectly?


  public partial class MainWindow : Window
    public ObservableCollection<string> TestOC = new ObservableCollection<string> { "First" };

    public MainWindow()

 the XAML file:

<Window x:Class="WpfApplication2.MainWindow"
    <ListView ItemsSource="{Binding TestOC}"/>

Shouldn't that just work?


calling a code behind method using xaml?


Is it possible to call a method in a XAML's code-behind through XAML itself? ie:

<Image Source="{Binding GetRandomImagePath}" />


public string GetRandomImagePath(...){////}


How to retrieve the original XAML file name from code



I would like to display the original filename for the element the mouse is hovering over. Can I retrieve the original XAML-FileName from a FrameworkElement in code?

Paul Sinnema

Take a look at my blog: http://paul.sinnema.ch
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