2017-02-06 9 views
0

私は周りを探索してXamarin Forumsに投稿し、Slackについて尋ねましたが、これをどうやって行うのか分かりませんでした。私はまたStackoverflowの投稿の束を見てきました。XamarinフォームのStackLayoutに機能ボタンを配置するにはどうすればよいですか?

私は、ScrollViewにあるStackLayoutにボタンを配置しようとしています。ファビコンイメージは単なるテストイメージです。私はそれが必要以上のスペースがあることを知っています。私はC#でこれをすべてやっています。

    new StackLayout 
        { 
         Padding = 0, 
         Orientation = StackOrientation.Horizontal, 
         Children = 
         { 
          new Label 
          { 
           Text = "• ", 
           TextColor = Color.Black, 
          }, 
          new Label 
          { 
           FontSize = 16, 
           Text = "Follow Surviving Sepsis Guidelines: ", 
           TextColor = Color.Black, 
           HorizontalOptions = LayoutOptions.Start 
          }, 

          new WebView 
          { 
           HeightRequest = 100, WidthRequest = 100, Source = "https://developer.android.com/favicon.ico", 
          }, 

          new Button 
          { 

          Text = "Surviving Sepsis Guidelines", 

          // Does not compile. "Invalid initializer member declarator" 
          Clicked += (sender,e) => 
          { 
          Device.OpenUri(new Uri("http://www.sccm.org/Documents/SSC-Guidelines.pdf")); 
          } 

          }, 
         } 
        }, 

答えて

1

これがあると回答。 "クリック"ではなく "コマンド"を使用してください。

Xamarin Forms Button OnClick

new Button { 
    Text = "Add parameters" 
    Command = new Command(() => { 
     //Do something 
    }) 
}; 

          new Button 
          { 

          Text = "Surviving Sepsis Guidelines", 


          Command = new Command(() => {Device.OpenUri(new Uri("http://www.sccm.org/Documents/SSC-Guidelines.pdf"));}) 

          }, 
0

私が正しく理解していますかどうかわからないですが、あなたは

XAMLやろうとしているものということです。

<ContentPage.Content> 
    <ScrollView> 
     <StackLayout> 
      <Button Text="Click me"/>    
     </StackLayout> 
    </ScrollView> 
</ContentPage.Content> 

のC#:

var scroll = new ScrollView(); 
Content = scroll; 
var stack = new StackLayout(); 
stack.Children.Add(new Button{ Text="Click Me" }); 
0

私はxamarin.formsでそれを行う方法は、これはあなたがScrollViewにStackLayoutを使用する方法である。この

var buttonnew = new Button 
     { 
      Text = "Click Me!", 
      BackgroundColor = Color.FromHex("FF5A5F"), 
      FontSize = 24     
     }; 


    buttonnew.Clicked += async (sender, args) => 
     { 
      buttonnew.IsEnabled = false; 
      // do your onclick process here 

     }; 

    MainPage = new ContentPage 
     {   
      BackgroundColor = Color.FromHex("BFD7EA"), 
      Content = new StackLayout 
      { 
       VerticalOptions = LayoutOptions.Center, 
       Children = { 

        buttonnew, 


       } 
      } 
     }; 
0

のようなものです。詳細については

<ScrollView BackgroundColor="Teal"> 
    <StackLayout Spacing="5" 
       Padding="30" 
       WidthRequest="400" 
       HorizontalOptions="Center" 
       VerticalOptions="CenterAndExpand" 
       BackgroundColor="Transparent"> 
     <Label Text="Test" HorizontalOptions="Center"/> 
     <StackLayout HorizontalOptions="Center"> 
      <Label Text="Test"/> 
     </StackLayout> 
    </StackLayout> 
</ScrollView> 

サンプルコードの多くがここにあります、this Xamarin documentationを参照してください。それが役に立てば幸い。

関連する問題