Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using large values in dependency properties (XAML)

Tags:

wpf

xaml

I have a user control with an exposed double dependency property. If I attempt to assign a large value to it:

<UserControl Value="98765432.10"/>

It builds and runs but I get the number "98765432.0" in the setter. Smaller values work fine. If I pass the same large number into the control using the code-behind, it also works fine.

Does XAML not parse doubles correctly?

like image 711
BradleyDotNET Avatar asked Nov 12 '22 16:11

BradleyDotNET


1 Answers

Try declaring the double value as a WindowResource. You'll need to import the "mscorlib" namespace.

<Window x:Class="WpfApplication5.Window1"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
 xmlns:core="clr-namespaceystem;assembly=mscorlib"  
 Title="Window1" Height="700" Width="900">

  <Window.Resources>  
    <core:Double x:Key="myDouble">98765432.10</core:Double> 
  </Window.Resources>

  <UserControl Value="{StaticResource myDouble}"/>  
</Window>
like image 72
d.moncada Avatar answered Nov 23 '22 22:11

d.moncada