C++开发uwp的坑

本文介绍了一个使用UWP(Universal Windows Platform)进行应用程序开发的例子,详细展示了如何创建按钮和文本块元素,并设置了它们的样式及交互行为,如字体大小、背景颜色等。此外,还介绍了如何为按钮添加点击事件处理程序以及实现文件选择器的功能。
摘要由CSDN通过智能技术生成
 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid x:Name="MyGrid">            
        </Grid>
    </Grid>

Button^ bt;
bt = ref new Button();
//控件必须初始化 ref new ;
//也可以 写在同一行
//auto bt= ref new Button();

tx->Margin =Windows::UI::Xaml::Thickness(100.f);


auto h = ref new Windows::Web::Http::HttpClient();
auto btn = ref new Button();
btn->Content = "an niu ";
btn->FontSize = 48;
btn->Foreground = ref new SolidColorBrush(Colors::Blue);
btn->Background = ref new SolidColorBrush(Colors::LightGreen);
btn->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Center;
//click速度慢于tapped
btn->Tapped += ref new Windows::UI::Xaml::Input::TappedEventHandler(this, &App2::MainPage::OnTapped);
auto tx = ref new TextBlock();
//tx->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Right;
tx->TextWrapping = Windows::UI::Xaml::TextWrapping::WrapWholeWords;
tx->TextAlignment = TextAlignment::Left;
//tx->OpticalMarginAlignment = OpticalMarginAlignment::None;
tx->Text = "TEXT";
tx->FontSize = Add(10, 38);
tx->Margin =Windows::UI::Xaml::Thickness(100.f);
tx->Foreground = ref new SolidColorBrush(Colors::PaleVioletRed);
MyGrid->Children->Append(tx);
MyGrid->Children->Append(btn);

void App2::MainPage::OnTapped(Platform::Object ^sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs ^e)
{
((Button^)sender)->Background = ref new SolidColorBrush(Colors::LightCyan);
((Button^)sender)->Foreground = ref new SolidColorBrush(Colors::Red);
auto fileopenpicker = ref new FileOpenPicker();
fileopenpicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
fileopenpicker->FileTypeFilter->Append(".pdf");
//fileopenpicker->CommitButtonText = "打开";//默认值是  打开
fileopenpicker->CommitButtonText = "是否tap你需要的文档,并确定";
fileopenpicker->ViewMode = PickerViewMode::List;
fileopenpicker->PickMultipleFilesAsync();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值