1

I want to implement to Vectore3 values as constants values in ResourcesDictionary but sadly an error just appears saying "Vector3 doesn't support direct content" Is there any way to do this??

Describing image

I expecting that Vector3 to be applied in xaml directly like x:Double, x:String ...etc

3
  • 1
    X:double is a markup extension that takes a content and sets value. Sys vector3 is not a markup extension so it unsurprisingly cannot set value from content. You would need to write your own markup extension.
    – Andy
    Commented Nov 10, 2022 at 19:08
  • Hi @Abd Alghani Albiek, did my answer help you? Commented Nov 30, 2022 at 7:19
  • @JunjieZhu-MSFT Yes it did, it gave me the reason why isn't accept any of beside these struct values, so I searched for another way to solve this problem, and I found very easy way to work around it, simply you can use binding for source (not ElementName or path) any of these data types that you mention them below then use converter to convert the actual value to the value that you want Commented Nov 30, 2022 at 15:06

2 Answers 2

1

Currently only four intrinsic data types are supported in UWP xaml.

  • x:Boolean
  • x:String
  • x:Double
  • x:Int32

you can get more information from this document XAML intrinsic data types.

So you can't use Vector3 in xaml, you need create this struct in your code behind.

0

As @JunjieZhu-MSFT mentioned above there is no way to make data type struct values beside those four, so I worked as follow:

<x:string x:key="ShadowOffsetXY">0 2 0</x:string>

Then I made class that implement IValueConverter to convert this string value to Vector3 Value

  public class StringToVector3Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null && value.GetType() == typeof(string))
            {
                var values = ((string)value).Split(" ");
                return new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]));
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }

Then use this converter in the property of control that I want to bound this source value from

<ui:Effects.Shadow>
   <media:AttachedCardShadow Offset="{Binding Source="{StaticResource ShadowOffsetXY}, Converter={StaticResource StringToVector3Converter}" }" />
</ui:Effects.Shadow>
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.