Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:42:55+00:00 2026-06-04T02:42:55+00:00

In a form in my WPF application, I am building a psuedo bar graph.

  • 0

In a form in my WPF application, I am building a psuedo bar graph. The bar graph consists of a Grid with 12 columns. Each column contains a Rectangle. I am using databinding to bind the height of the rectangle to the data that I want to graph. The xaml looks like this:

<Border BorderBrush="{DynamicResource ControlBorder}"
        BorderThickness="2"
        Grid.Column="1"
        Grid.Row="0"
        Margin="0,5"
        Name="SNRGraphBorder">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Rectangle Fill="{DynamicResource TextForeground}"
                   Grid.Column="0"
                   Margin="1,5,2,0"
                   Name="Data01"
                   VerticalAlignment="Bottom">
            <Rectangle.Height>
                <MultiBinding Converter="{StaticResource ScaleData}">
                    <Binding Source="{StaticResource XmlProvider}"
                             XPath="a:PathToData}" />
                    <Binding Path="RectangleHeight"
                             RelativeSource="{RelativeSource AncestorType={x:Type cs:MyControl}}" />
                </MultiBinding>
            </Rectangle.Height>
        </Rectangle>
        . . .
    </Grid>
</Border>

I’ve only included one rectangle for brevity.

Here’s the code for the IMultiValueConverter used in the MultiBinding:

public class ScaleDataConverter : IMultiValueConverter {

    public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
        double snr = 0.0;

        if ( values[ 0 ] is string ) {
            snr = double.Parse( values[ 0 ] as string );

        } else if ( values[ 0 ] is int || values[ 0 ] is double || values[ 0 ] is long || values[ 0 ] is float ) {
            snr = (double) values[ 0 ];
        } else {
            return values[ 0 ];
        }

        double ActualHeight = (double) values[ 1 ];
        return snr * ActualHeight / 99.0;
    }

    public object[] ConvertBack( object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture ) {
        throw new NotImplementedException();
    }

}

Finally, here’s the code behind for this control:

public partial class MyControl : UserControl {

    public XmlDataProvider DataProvider { get; set; }

    public DeviceMonitor DeviceMonitor { get; set; }

    public double RectangleHeight {
        get { return SNRGraphBorder.ActualHeight; }
    }

    public MyControl() {
        InitializeComponent();
        DataProvider = Resources[ "XmlProvider" ] as XmlDataProvider; 
    }

    private void GetDiagnosticsInfo() {
        if ( DeviceMonitor != null ) {
            XmlDocument diagnosticsDoc = new XmlDocument();
            string info = DeviceMonitor.GetDiagnosticInfo();
            diagnosticsDoc.LoadXml( info );
            DataProvider.Document = diagnosticsDoc;
        }
    }

    private void RefreshButton_Click( object sender, RoutedEventArgs e ) {
        GetDiagnosticsInfo();
        e.Handled = true;
    }
}

I’ve put breakpoints into the converter on the if ( values[ 0 ] is string ) line. I see that the first entry in the values array is always DependencyProperty.UnsetValue. Yet I know that the XML has other data for this property. What am I doing wrong?

Thanks

Tony

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:42:57+00:00Added an answer on June 4, 2026 at 2:42 am

    I’ve been able to resolve the issue. If you look closely at the XPath in the first multi binding, you’ll see that it ends in a “}”. That character is not actually a part of the XPath, it is a left-over from the original text for the binding when it was a single binding using the {Binding Source={…} XPath=….} syntax. Once I removed it, I stopped getting DependencyProperty.UnsetValue for the first value in the values array.

    I was also able to resolve the other issue with the second value being zero. I made the RectangleHeight property a DependencyProperty and added code in the Loaded event handler to set it equal to the actual height of the Grid control that contains all of the Rectangles. Now my code works and I get a lovely bar graph.

    Thanks all who looked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WPF for creating my application, I am calling a windows form using
I have a windows form control inside wpf application using a windows forms host.
In the entry form of my wpf application, I have a list of buttons
I have window form in my WPF Application when I open new window from
I have WPF Application where I have One main form and other user controls
I just built a WPF form that contains a ListBox. The ListBox has bound
I'm using Visual Studio 2010 to create a small WPF application. I've created a
(learning c#) I have a C# WPF application which when a certain form is
I'm working on an WPF application using the mvvm-light framework. I'm new to both
I have a WPF application that hosts a modeless Win32 form. Everything runs smoothly,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.