.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

Databinding: Is code behind considered Imperative and is XAML considered Declaritive?

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :JQuery
I'm just learning WPF and I wanted to know if databinding via code behind (create binding object, set properties, etc) is considered imperative programming and if the use of XAML extensions is considered declaritive programming.   I know the question is a bit odd, after all, who cares what it's called.  I'm just curious - I need to learn the lingo.  :D

View Complete Post

More Related Resource Links

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.

XML databinding - accessing attributes of ParentNode from childNode in XAML

Hi All, I would like to get the ParentNode of a given childNode for the xml databinding in XAML. So what should I do ??? For instance: [XML] <Answer           Margin="40,1,1,1"           TabIndex="4"           Name="Answer"           DataType="bool"           Value="N">           <Option             Name="Y"             DisplayText="Yes"             MaxLength="1"             Width="20" />           <Option             Name="N"             DisplayText="No"             MaxLength="1"             Width="

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?  

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!

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

DataBinding and Code-Behind


I have a question about doing something with binding to a control and then doing some processing in the code-behind based on that binded information. I wasn't sure if it were possible, if it is I'd like to know how to do.

Alright, here's the general scenario.

I binded an Sql query to a DataBind control, doesn't matter what I guess, Repeater, DataList, ListView, whatever.

<asp:Repeater ID="Test" runat="server"?
       <%# Eval("Test") %>

       <asp:Button ID="btnTest" OnClick="btnTest_Click" runat="server" />


Something like that. The MAIN thing I really want to do is when I click btnTest I want to do some processing based on the information I've bounded to the Repeater. For instance I'll already have a SELECT statement that selects an ID and whatever else. I just want to take that ID ( based on that particular entry of course ), do some other data processing based on that ID, and other crap. So how would I do this?

Is it possible? Am I doing this wrong? What would you do in a situation like this? I'm fairly new to ASP and I don't know the nifty tricks most everyone knows.

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"

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?


DataBinding not updating underlying business object when changing control property from code


I have a custom data form control that in code generates databindings between the selected custom business object (LLBL) and the various controls on the screen. Everything works in that I set the DataContext to the selected business object and the data appears in the GUI. If the user changes anything on screen, the data is getting updated into the business object.

However, now I have some custom logic that when the user presses a button I need to update some fields. Currently I'm setting this data directly into the controls, setting the new value into the property that is bound. However, the data is not getting pushed back into the business object.  I had this same issue building WinForm apps in that databinding only fired if the user was in the control and left it.

Does the same thing apply to WPF? How can I get ANY change on say a TextBox's Text property whether via user interaction or from C# code to push that value into the bound business object property?


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

How to use 2 xaml files with one code behind


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?



How read flowdocument xaml to make available in vb code


I'm very very new to WPF and not particularly experienced in VB.Net (mostly a VBA man) so forgive me if this comes across as completely idiotic, cause it more than likely is :-( .....

The problem I have is that I want the user to have the ability to insert buttons into a richtextbox and be able to put essentially as many buttons as they like in and amongst some text.... simple enough....

Problem is I'm finding this impossible with my limitted knowledge of anything WPF related.....

I can use the following code to allow the user to double click in the rtb at a certain point and the code will go off and create a flowdocument (in vb) with an inline container with a button in it and then merge the text from the rtb with the flowdocument.... 



 Dim WithEvents aButton As TextBox = New TextBox (class level variable)

Dim aFlowDocument As FlowDocument = New FlowDocument

Dim bparagraph As Paragraph = New Paragraph

        bparagraph.Inlines.Add(New InlineUIContainer(aButton))




Designer does not remember my settings, for ex., I want to always load xaml into xaml (code) view, n


I am using VS 2010 Ultimate.  It is not remembering my setup when opening .xaml files.  It is very annonying.  I  am pretty sure VS remembers things like that.

I prefer to load my .xaml file to see the code only.  So I usually minimize the design tab.  However, I have to do this every time I open a .xaml file.

I am getting the feeling this setting is stored at the .sln level, which is even more annonying, it should be global setting for all VS sessions.

Any advice?

"Async Callback exception causes w3wp to crash" when hosting a workflow in IIS is considered "Resolv


A connect case regarding workflows hosted in IIS as been marked resolved as by design. See connect ID 558275 "Async Callback exception causes w3wp to crash when loading old instances of workflows in WorkflowServiceHost".

This seems like a really lame resolution to me.  Is there any avenue of appeal for the design of this implementation?  Does anyone else in the community share my distaste for the current harsh exception handling of tearing down the whole w3wp.exe just due to an error in one particular .xamlx?  I think this forum has better traffic than connect so I'm hoping that if a few more people get exposed to this issue the community can provide additional feedback that might be missed on connect.

I know that AppFabric is not yet RTM, so I hope there is still time to get this addressed maybe as part of the AppFabric release even if it requires a change in the core 4.0 bits.  It seems like there is already a presumption that if you are hosting in IIS you will use AppFabric so I would find it acceptable if the AppFabric release had a better more robust solution when a single workflow gets in a bad state.

See http://connect.microsoft.com/VisualStudio/feedback/details/558275/async-callback-exception-causes-w3wp-to-crash-when-loading-old-instances-of-workflows-in-workflowservicehost 

Anybody else have any thou

Disable Kernel-Mode for Kerberos. Is this considered a best practice?


It is suggested in the following two posts, by MSFT folks, that for Kerberos to work you have to DISABLE Kernel-Mode.  Is this then considered a "Best Practice"?






ActivityBuilder or DynamicActivity for authoring workflow using imperative code


Hi all, 

I'm currently investigating what's the best way to author a workflow using imperative code. I found this link :


but, I'm still curious, which one is better as the main ingredient to author workflow using imperative code, is it ActivityBuilder or DynamicActivity?

The requirement is to write a workflow but we don't need it to be a type. We want to execute the created workflow, as well as perform modification (using code) such as adding/deleting argument, modify the variable, add/delete the sequence etc.

What are the differences between ActivityBuilder and DynamicActivity?

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