stack - 你知道按下了哪个按钮(Xamarin.Forms)
问题描述
当我单击创建项目按钮时,以编程方式创建了一个按钮,但是有一个问题,因为我无法以任何方式获取按钮的名称,请提前帮助我谢谢如何找出按下了哪个按钮一个人,但是一个人可以自己创建这些按钮,嗯,有必要做一些操作
MainPage.xaml.cs
namespace RowCounter.Forms
{
public partial class MainPage : ContentPage
{
public int Number = 0;
public string NAME = null;
public int Name_Number = 0;
public string[] NAME_MAS = {" "};
public int[] Number_Mas = {1};
public int Number_Button = 0;
public MainPage()
{
InitializeComponent();
}
private void OnButtonClicked(object sender, EventArgs e)
{
popupLoginView.IsVisible = true;
}
private void OnButtonClicked_Name(object sender, EventArgs e)
{
Number++;
NAME = NAME_PROJECT.Text;
Array.Resize(ref Number_Mas, Number_Mas.Length + 1);
Array.Resize(ref NAME_MAS, NAME_MAS.Length + 1);
Name_Number++;
NAME_MAS[Name_Number] = NAME;
Number_Mas[Name_Number] = Number_Button;
popupLoginView.IsVisible = false;
Button button3 = new Button
{
Text = Number +".",
WidthRequest = 40,
HorizontalOptions = LayoutOptions.Start
};
Button button = new Button
{
Text = " "+ NAME,
TextColor = Color.Red,
WidthRequest = 450,
HorizontalOptions = LayoutOptions.Start
};
Button button2 = new Button
{
Text = "X",
WidthRequest = 40,
HorizontalOptions = LayoutOptions.End
};
Button button4 = new Button
{
Text = Number_Button +"",
WidthRequest = 40,
HorizontalOptions = LayoutOptions.End
};
MainGrid.Children.Add(button, left: 0, top: Number);
MainGrid.Children.Add(button2, left: 1, top: Number);
MainGrid.Children.Add(button3, left: 0, top: Number);
MainGrid.Children.Add(button4, left: 0, top: Number);
}
}
}
主页.xaml
<?xaml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RowCounter.Forms.MainPage"
BackgroundColor="#9370db">
<Grid x:Name="MainGrid" VerticalOptions="StartAndExpand">
<Button Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="0"
Text="create project"
FontAttributes="Bold"
FontSize="25"
WidthRequest="250"
HeightRequest="80"
Clicked="OnButtonClicked"
TextColor="#ff000000"
BackgroundColor="#4b0082"/>
<ContentView x:Name="popupLoginView" BackgroundColor="#C0808080" Padding="10, 0" IsVisible="false" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<StackLayout Orientation="Vertical" HeightRequest="200" WidthRequest="300" BackgroundColor="White">
<Entry x:Name="NAME_PROJECT" Margin="20,20,20,10" Placeholder="Name project"></Entry>
<Button Margin="20,0,20,0" Text="Ок" Clicked="OnButtonClicked_Name"></Button>
</StackLayout>
</StackLayout>
</ContentView>
</Grid>
</ContentPage>
我搜索了一半的网络,一无所获!
解决方案
推荐阅读
- r - 当分数相同时选择具有优先级的观察
- python - pyside2 加载 qt 调试库
- ios - SwiftUI中出现键盘时如何避免View移出屏幕?
- maven - 部署到 Nexus 时,父 POM 未展平
- javascript - JS数组查找值
- caching - 缓存调用微服务的结果
- html - Bootstrap 5 - 在表单控件内定位浮动标签,宽度:自动?
- python - Python 用 beautifulsoup 抓取不能正确抓取一些数据行
- vb.net - VB.NET 在剪贴板上复制多个文件并粘贴到它们的文件夹中
- python-3.x - 与 PyPDF2 结合使用的拖放功能问题