2017-12-15 13 views
0

그래서 만든 사용자 지정 내가 사용자 정의 컨트롤의 사용했다, 그것은 재사용하기 위해, UWP에 대화 상자가 나타재사용 가능한 사용자 지정 팝업 대화를 만들려면

<UserControl 
    x:Class="ContentDialogueBox.PopUpCustomDialogueUserControl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:ContentDialogueBox" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" 
    d:DesignWidth="400"> 


    <ContentDialog x:Name="MyContentDialogCustom" 
        VerticalAlignment="Stretch" 
        HorizontalAlignment="Stretch" 
        Title="Lorem Ipsum" 
        PrimaryButtonText="OKxxx" 

        SecondaryButtonText="Canc" 
        Margin="0,0,-98,0" Width="1000" > 
     <Grid Background="Wheat"> 


      <Grid.ColumnDefinitions> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition/> 
       <RowDefinition/> 
       <RowDefinition/> 
      </Grid.RowDefinitions> 
      <TextBlock Text="Name" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
      <TextBox PlaceholderText="First Name" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="10"/> 

      <TextBlock Text="Middle Name" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"/> 
      <TextBox PlaceholderText="Middle Name" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="10"/> 

      <TextBlock Grid.Row="2" Text="Name" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
      <TextBox PlaceholderText="First Name" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="10"/> 



     </Grid> 
    </ContentDialog> 
</UserControl> 

난을 참조 할 수 있었다 ButtonShowContentDialog4라는 버튼이 포함 된 다른 페이지의 사용자 컨트롤, 내가 달성하고자하는 것은 페이지의 버튼을 클릭 할 때 PopUp 대화 상자를 표시하는 것입니다. 제발 어떻게 이것을 달성합니까.

private void ButtonShowContentDialog4_Click(object sender, RoutedEventArgs e) 
{ 
     //show the PopUp here when this button is clicked 
} 

답변

0

두 가지 방법으로 달성 할 수 있습니다. 그렇다 당신은 사용자 컨트롤 내부를 넣는 대신 사용자 정의 ContentDialog을 만들었습니다 수있는 일에서, 당신은 아마이 같은 목표를 달성 할 수

당신의 PopUpCustomDialogueUserControl 클래스에 팝업을 표시 할 방법을 정의 : 당신이 그것을 일단

public async Task ShowMyDialog() => await MyContentDialogCustom.ShowAsync(); 

, XAML에 페이지에 somwhere 당신의 PopUpCustomDialogueUserControl를 추가 (에게 (적절한 네임 스페이스를 추가하도록 ContentDial 기억 ogueBox는) 지역 다음과 같이 정의)와 그것을 이름 추가

내가 통해 UR 솔루션을 시도
private async void ButtonShowContentDialog4_Click(object sender, RoutedEventArgs e) 
{ 
    await MyCustomDialog.ShowMyDialog(); 
} 
+0

, 팝 업이었다

<local:PopUpCustomDialogueUserControl x:Name="MyCustomDialog"/> 

는 그런 다음 코드에서의 메서드를 호출 할 수 있습니다 화면에 보이지 않습니다. –

+0

@OsamuyimenOsagiedeDennis 내가 한 일을 잘 모르겠지만 코드를 복사하여 붙여 넣으면 위에서와 같이 작동하는 것 같습니다. – Romasz

+0

오케이, 제대로 점검하고 피드백을 주겠다. 많은 시간을 내 주셔서 감사합니다. –