Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过编程设置xamarin uwp中按钮的角半径?_Xamarin_Xamarin.forms_Uwp_Xamarin.uwp - Fatal编程技术网

如何通过编程设置xamarin uwp中按钮的角半径?

如何通过编程设置xamarin uwp中按钮的角半径?,xamarin,xamarin.forms,uwp,xamarin.uwp,Xamarin,Xamarin.forms,Uwp,Xamarin.uwp,我有一个网格控制按钮。我想通过在xamarin.uwp中编程设置此按钮的角半径。如果可能的话,我想设置左下角的角半径。请就这个问题提出你的想法 根据您的需求,您可以自定义左下角BindableProperty。然后在自定义按钮渲染中使用它,如下所示 自定义表单按钮 公共类MyButton:按钮 { 公共静态只读BindableProperty BottomLeftProperty=BindableProperty.Create( propertyName:“左下角”, returnType:ty

我有一个网格控制按钮。我想通过在xamarin.uwp中编程设置此按钮的角半径。如果可能的话,我想设置左下角的角半径。请就这个问题提出你的想法

根据您的需求,您可以自定义
左下角
BindableProperty
。然后在自定义按钮渲染中使用它,如下所示

自定义表单按钮

公共类MyButton:按钮
{
公共静态只读BindableProperty BottomLeftProperty=BindableProperty.Create(
propertyName:“左下角”,
returnType:typeof(int),
declaringType:typeof(我的按钮),
defaultValue:default(int));
公共int左下角
{
获取{return(int)GetValue(BottomLeftProperty);}
set{SetValue(BottomLeftProperty,value);}
}
}
CustomButtonRenderer.cs

公共类CustomButtonRenderer:ButtonRenderer
{
Windows.UI.Xaml.Controls.ContentPresenter\u ContentPresenter;
MyButton\u myElement;
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(Control==null)
{
SetNativeControl(新表单按钮());
}
if(例如NewElement!=null)
{
Control.Loaded+=控件\u Loaded;
_myElement=作为MyButton的元素;
}
}
受保护的覆盖无效OnElementPropertyChanged(对象发送方,PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(发送方,e);
if(e.PropertyName==MyButton.BottomLeftProperty.PropertyName)
{
UpdateBottomLeftBorderRadius(_myElement.BottomLeft);
}
}
已加载私有无效控件(对象发送方,Windows.UI.Xaml.RoutedEventArgs e)
{
_contentPresenter=MyFindChildByName(控件,“contentPresenter”)为Windows.UI.Xaml.Controls.contentPresenter;
if(_myElement.IsSet(MyButton.BottomLeftProperty)&&&u myElement.BottomLeft!=(int)MyButton.BottomLeftProperty.DefaultValue)
{
UpdateBottomLeftBorderRadius(_myElement.BottomLeft);
}
}
私有void UpdateBottomLeftBorderRadius(int左下角)
{
如果(_contentPresenter!=null)
{
_contentPresenter.CornerRadius=新的CornerRadius(0,0,0,左下角);
}
}
公共静态DependencyObject MyFindChildByName(DependencyObject parant,string ControlName)
{
int count=VisualTreeHelper.GetChildrenCount(parant);
for(int i=0;i
用法

<local:MyButton x:Name="Hello" Text="hello" 
                WidthRequest="100" 
                HeightRequest="100"  
                Margin="0,100,0,0" 
                BottomLeft="15" 
                VerticalOptions="Center" 
                HorizontalOptions="Center" 
                Clicked="MyButton_Clicked"/>

您是否只想设置左下角半径?是的,左下角和右下角@NicoZhu MSFThi@KarthikRj是否有效?
HelloBtn.BottomLeft = 30;