Solved

Dynamic calculating constants in a Resource Dictionary

Posted on 2008-10-14
2
922 Views
Last Modified: 2013-11-12
Have this Xaml constant (XamlConstants.cs) and it dynamicaly creates other constants from other values:
        #region Fields
        const double ADJUSTMENT = -1;
        const double COL_DELTA = 190;
        const double LBL_TXT_DELTA = 75;
        const double ROW_DELTA = 30;
        const double TXT_CHK_DELTA = 3;
        const double TXT_ROW1 = 2;
        #endregion

        #region Public Constants
        public const double BTN_HEIGHT = 23;
        public const double BTN_WIDTH = 75;
        public const double LBL_HEIGHT = 28;
        public const double LBL_WIDTH = 54;
        public const double LBL_WIDTH_X2 = LBL_WIDTH * 2;
                    :
        public const double ROW_HEIGHT = ROW_DELTA - 1;
        public const double ROW_HEIGHT_X2 = (ROW_DELTA * 2) + ADJUSTMENT;
                    :
        public const double ROW_HEIGHT_X5 = (ROW_DELTA * 5) + ADJUSTMENT;
        public const double TXT_HEIGHT = 21;
        public const double TXT_WIDTH = 90;
        public const double TXT_WIDTH_SMALL = TXT_WIDTH / 2;
        public const double TXT_WIDTH_TINY = TXT_WIDTH_SMALL / 2;
                     :
        public const double TXT_WIDTH_X4 = TXT_WIDTH * 4;
        #endregion

I want to move this to a Resource Dictionary

I'm able to do this:
    <!--    Labels      -->
    <Style TargetType="Label" x:Key="lblBase">
        <Setter Property="Height" Value="28" />
    </Style>
    <Style TargetType="Label"     x:Key="lblStd">
        <Setter Property="Height" Value="{DynamicResource lblBase.Height}" />
        <Setter Property="Width"  Value="54" />
    </Style>
    <Style TargetType="Label"     x:Key="lblStd_X2">
        <Setter Property="Height" Value="{DynamicResource lblBase.Height}" />
        <Setter Property="Width"  Value="108" />

But I want the width of lblStd_X2 to be represented as something like lblStd.Width*2 - How do I do that?

Thanks
0
Comment
Question by:Marvin_Rowe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
adler77 earned 500 total points
ID: 22728308
I know there are more options with WPF, but I am more familiar with the SL side (which should also work in WPF). I haven't tried it, since SL doesn't support DynamicResource, but could you do a value converter (http://www.jeff.wilcox.name/2008/07/13/visibility-type-converter/)?

Similar to the example I linked to, except your value would be "{DynamicResource lblStd.Width, Converter={StaticResource WidthDoubler}}" and then the VisibilityConverter would be set up the same (named WidthDoubler) except Convert would look like the code below:
public object Convert(   
        object value,   
        Type targetType,   
        object parameter,   
        CultureInfo culture)   
    {   
        double stdwidth = (double)value;   
        return stdwidth * 2;   
    }   

Open in new window

0
 

Author Comment

by:Marvin_Rowe
ID: 22729561
Help me understand how this solution is different from using Xaml constants (above), which I was able to do but wanted to move the logic from a Xaml constant to a Resource Dictionary.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question