ccdmfc
ccdmfc

Reputation: 63

Xamarin Forms UWP specifying button width request with an effect

I would like to specify the width of a Xamarin.Forms.Button with an effect in UWP, something like:

protected override void OnAttached()
{
    if (VisualElement is Xamarin.Forms.Button buttonControl)
    {
        buttonControl.WidthRequest = 40;
        buttonControl.BorderWidth = 1;
    }
}

VisualElement is an invalid type. What goes in its place? Thank you!

Upvotes: 0

Views: 67

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

Xamarin Forms UWP specifying button width request with an effect

In Xamarin effect class, the attached control is referenced with Element property but not VisualElement, please edit your code like the following and you will get forms button on OnAttached method.

protected override void OnAttached()
{
    if (Element is Xamarin.Forms.Button buttonControl)
    {
        buttonControl.WidthRequest = 40;
        buttonControl.BorderWidth = 1;
    }      
}

Upvotes: 1

Related Questions