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


Top 5 Contributors of the Month
david stephan
Fauzul Azmi
Asad Ali
Post New Web Links

Conditional Binding with XAML

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

Hello,

I have just started to work with silverlight application in Expression Blend 4.

I have a label contains a number, and I want to fill a rectangle with the right color. For example, if the content is above 90 to fill it with green, and so on, but I dont know how to do it.

Thank in advance for your help.




View Complete Post


More Related Resource Links

Data binding without typing out xaml

  
Now I'm not stumped on getting data binding to work, I simply want to know how to utilize the window interfaces that visual studio 2010 comes with - as opposed to typing in XAML.  All I want to do is bind a font size property to an xml file within the project.   Here's what I do: After selecting the text box, in the properties panel, i go to the text category then click on the data-binding icon next to the font size field.  I then click on 'apply data binding', where a small panel pops up.  This is where I become stuck.  It seems like I need a path to the xml file, but I don't know how to add that in without typing in XAML.  I would assume that I would be able to add in a resource somewhere - kind of like windows forms allow me to do. I've never worked with WPF before, so I know it's something small/simple that i'm missing.  Any help would be appreciated. thanks, Phil

Data binding without typing out xaml

  
Now I'm not stumped on getting data binding to work, I simply want to know how to utilize the window interfaces that visual studio 2010 comes with - as opposed to typing in XAML.  All I want to do is bind a font size property to an xml file within the project.   Here's what I do: After selecting the text box, in the properties panel, i go to the text category then click on the data-binding icon next to the font size field.  I then click on 'apply data binding', where a small panel pops up.  This is where I become stuck.  It seems like I need a path to the xml file, but I don't know how to add that in without typing in XAML.  I would assume that I would be able to add in a resource somewhere - kind of like windows forms allow me to do. I've never worked with WPF before, so I know it's something small/simple that i'm missing.  Any help would be appreciated. thanks, Phil

Binding a custom type in XAML ?

  
Hi, I'd like to bind a property "myProperty" of type "MyType" in the text property of TextBlock : <TextBlock Text="{Binding myProperty, Mode=OneWay}" And I overrided the ctype operator to have conversion from "MyType" to String: Public Overloads Shared Narrowing Operator CType(ByVal v As MyType) As String ...................... End Operator But it seems not work! I get the ToString of "MyType" in result but not the return of CType operator. Is it normal ? Why ?   Thanks for your help.  

Dynamically Assign Datagrid Column Binding from XAML

  

I am trying to build a generic user control that will serve as a quick list maintenance screen.

I have a base ViewModel that has two string properties IDColumnName and DisplayColumnName and then a collection of objects to be edited.  Inherited view models will be created for each object type that needs to be maintained.  The usercontrols datacontext is set to the viewmodel.

What I want to do is have the datagrid, who's itemssource is bound to the collection of objects in the viewmodel, have one column and have that one column bound to the property specified in the DisplayColumnName property of the viewmodel, and I'd like to do it all in XAML.  I've got the datagrids rowdetailstemplate being dynamically determined based on the object type but am struggling with dynamically setting which property the one column displays.


Binding Question How does one set datacontext to same class in XAML?

  

I have a usercontrol with one button in it.  I want to set the text via a property getter setter using the INotifyPropertyChanged interface in code behind.  I can get it to work if I set the DATACONTEXT in code behind in the CTOR like this : DataContext = this;  Everything works perfect. 

But here's the problem.  If I try to do this in xaml by defining an XMLNS which points to the folder this usercontrol is in, and then attempt to reference it as a resouce like this <local:XXXXXX  <-------The XXXX which is the class name of this control can't be found?  Is that wierd?  Can't a resource be itself?  So that I can set the Datacontext in the XAML instead of code behind?  I've tried to bind to relative source self, but cannot set the property (Event when I attempted to created a dependency property).....  Just wondering how one sets up Datacontext to the same class? 


Javaman

Binding Datatable to listview in Xaml

  

Hi,

  Can any one give me solution for below code.  I know how to bind the datatable to listview in code behind, but  i don't know, how to bind it through XAML. This is my sample code. Please any one help me.

<Window x:Class="ListViewDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ListViewControl;assembly=ListViewControl"
xmlns:local="clr-namespace:ListViewDemo"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="checkBox">
<CheckBox IsChecked="{Binding Path=Check, Mode=TwoWay}"/>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView Name="lvProcess">
<ListView.View>
<GridView>
<GridViewColumn Header="Dep_Type" DisplayMemberBinding="{Binding Path=Dep_Type}"/>
<GridViewColumn Header="Check" DisplayMemberBinding="{Binding Path=Check}"/>
<GridViewColumn Header="Depend

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?

MainWindow.xaml.cs

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

    public MainWindow()
    {
      InitializeComponent();
      TestOC.Add("Second");     
    }

 the XAML file:

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

Shouldn't that just work?

 

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"
    ...
>

    <UserControl.Resources>
        ...
    </UserControl.Resources>

    <ComboBox
        ...
        IsSynchronizedWithCurrentItem="True"
        ItemsSource="{Binding ElementName=UserControl, Path=ItemsSource}"
        DataContext="{Binding ElementName=UserControl, Path=DataContext}"
        >

        <ComboBox.ItemTemplate>
            <HierarchicalDataTemplate>
                <CheckBox Content="{Binding Title}"
                          IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
                          Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
                          Click="CheckBox_Click"
                          />
            </HierarchicalDataTemplate>
        </ComboBox.ItemTemplate>

        <ComboBox.Template>
            <ControlTemplate TargetType="ComboBox">
                &l

Binding WPF Controls to an Entity Data Model

  
In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

  
Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Binding WPF Controls to an Entity Data Model

  
In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Using Conditional Split data Transfer in SSIS 2008

  
This article uses the Integration Services Conditional Split Data Transformation element to filter and transfer data from a set of flat text files to SQL Server database table. The concept can be easily extended to apply to any other source or destination such as Microsoft Excel. This scenario is useful in creating denormalized database tables in a reporting and analysis situation.

WPF / Silverlight tutorial: Visibility property and binding

  
Visibility property is a very powerful and yet often overlooked property available in both WPF and Silverlight. It enables you to set Visibility of certain UIElement objects to different states like: Visible, Collapsed and Hidden (not supported by Silverlight). This tutorial shows you how to use it and how to bind to Visibility property

What's new in XAML of .NET 4.0

  
With .NET 4.0 Microsoft will bring up a improved version of XAML. This arcitle shows you the language enhancements they made.
Easy Object References with {x:Reference}

Built-in Types

Generics in XAML with x:TypeArguments

Support for Arbitrary Dictionary Keys

Use of Non-Default Constructors with x:Arguments

Use of Static Factory Methods with x:FactoryMethod

Binding an array to dropdown list

  

I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      

 

allLinks = newAllLinks
        Me.DropDownList1.Items.Clear()
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks
        Me.DropDownList1.DataBind()


 

 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8
   System


Binding Nested Listviews in MVC ViewPage

  

I am a longtime .NET developer but for big applications and services.  This is my first asp.net project and I have chosen MVC.   I have a need for nesting a ListView within a ListView.  In this simple catalog app, I have EF 4 Entities that are Categories, SubCategories, ItemTypes, and Items.

My goal is to display a 5 column layout of SubCategories with their ItemTypes below them in a ViewPage.  I did just fine with it done out in C# as server directives such as:

    var subcats = Model.SubCategory.ToArray();
    var nrSubCats = subcats.Count();
    var rows = (nrSubCats/5) + (((nrSubCats % 5) > 0) ? 1 : 0);
    for (var row = 0; row < rows; row++)
    { %>
        <div style="width: 100%; float: left; clear: right;">
        <%
        var start = row * 5;
        for (var i = start; (i < start + 5) && (i < nrSubCats); i++)
        {
        var subcat = subcats[i];
        %>
            <div style="float: left; clear: right; width: 20%; margin-left: 5;">
                <h2> <%:subcat.Name%></h2>
                <ul>
                    <%
                    foreach (var its in subcat.ItemType)
                    {%>
                        <li>
                            <%:Html.

Inline conditional output

  

Is it possible to somehow output some content based upon some conditional check in Razor? If not, I hope this possibility will be added in the future. What I want to do is the following:

<option value="1" @if(ListMode == 1) { = "selected=\"true\"" }>Full list</option>


As I can't figure out a way to do this, I have to either make a helper that does it for me or write duplicate code.


Categories: 
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