麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

WPF氣泡樣式彈窗效果代碼分享

2024-07-10 13:31:19
字體:
來源:轉載
供稿:網友

頁面設計需求,做了一個氣泡形狀的彈出框,效果如下:

 WPF氣泡樣式彈窗,WPF氣泡彈窗,WPF彈窗,WPF氣泡

設計思路如下:

1. 使用Path繪制氣泡的尖尖,將這個放到頂層;

2. 在用border繪制長方形框,將這個放到底層,并且設置Margin值,使得Path圖層和border看起來銜接在一起。 

代碼如下:

<Window x:Class="BubblePanelTest.MainWindow"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <Window.Resources>  <Style TargetType="Label" x:Key="TopBubblePanel">   <Setter Property="Template">    <Setter.Value>     <ControlTemplate TargetType="{x:Type Label}">      <Grid>       <Border CornerRadius="4" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top" Background="Yellow" HorizontalAlignment="Left" Margin="0,8.5,0,0" Padding="5">        <ContentPresenter />       </Border>       <Canvas Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,0,0,0" Background="Transparent">        <Path Stroke="Black" StrokeThickness="0.5" Fill="Yellow">         <Path.Data>          <PathGeometry Figures="M 0,10         L 0,10,5,0         L 5,0,10,10         "/>         </Path.Data>        </Path>       </Canvas>      </Grid>     </ControlTemplate>    </Setter.Value>   </Setter>  </Style>  <Style TargetType="Label" x:Key="BottomBubblePanel">   <Setter Property="Template">    <Setter.Value>     <ControlTemplate TargetType="{x:Type Label}">      <Grid>       <Border CornerRadius="4" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Bottom" Margin="0,0,0,8.5" Background="Yellow" HorizontalAlignment="Left" Padding="5">        <ContentPresenter />       </Border>       <Canvas Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10,0,0,0" Background="Transparent">        <Path Stroke="Black" StrokeThickness="0.5" Fill="Yellow">         <Path.Data>          <PathGeometry Figures="M 0,0         L 0,0,5,10         L 5,10,10,0         "/>         </Path.Data>        </Path>       </Canvas>      </Grid>     </ControlTemplate>    </Setter.Value>   </Setter>  </Style>  <Style TargetType="Label" x:Key="LeftBubblePanel">   <Setter Property="Template">    <Setter.Value>     <ControlTemplate TargetType="{x:Type Label}">      <Grid>       <Border CornerRadius="4" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top" Margin="8.5,0,0,0" Background="Yellow" HorizontalAlignment="Left" Padding="5">        <ContentPresenter />       </Border>       <Canvas Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10,0,0" Background="Transparent">        <Path Stroke="Black" StrokeThickness="0.5" Fill="Yellow">         <Path.Data>          <PathGeometry Figures="M 10,0         L 10,0,0,5         L 0,5,10,10         "/>         </Path.Data>        </Path>       </Canvas>      </Grid>     </ControlTemplate>    </Setter.Value>   </Setter>  </Style>  <Style TargetType="Label" x:Key="RightBubblePanel">   <Setter Property="Template">    <Setter.Value>     <ControlTemplate TargetType="{x:Type Label}">      <Grid HorizontalAlignment="Left">       <Border CornerRadius="4" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,8.5,0" Background="Yellow" Padding="5">        <ContentPresenter />       </Border>       <Canvas Width="10" Height="10" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,0,0" Background="Transparent">        <Path Stroke="Black" StrokeThickness="0.5" Fill="Yellow">         <Path.Data>          <PathGeometry Figures="M 0,0         L 0,0,10,5         L 10,5,0,10         "/>         </Path.Data>        </Path>       </Canvas>      </Grid>     </ControlTemplate>    </Setter.Value>   </Setter>  </Style> </Window.Resources> <StackPanel>  <Label Style="{StaticResource TopBubblePanel}" Tag="Top" Margin="2">   <StackPanel>    <StackPanel Orientation="Horizontal">     <TextBlock Text="abc" />     <TextBox Width="80"/>    </StackPanel>   </StackPanel>  </Label>  <Label Style="{StaticResource BottomBubblePanel}" Tag="Top" Margin="2">   <StackPanel>    <StackPanel Orientation="Horizontal">     <TextBlock Text="abc" />     <TextBox Width="80"/>    </StackPanel>   </StackPanel>  </Label>  <Label Style="{StaticResource LeftBubblePanel}" Tag="Top" Margin="2">   <StackPanel>    <StackPanel Orientation="Horizontal">     <TextBlock Text="abc" />     <TextBox Width="80"/>    </StackPanel>   </StackPanel>  </Label>  <Label Style="{StaticResource RightBubblePanel}" Tag="Top" Margin="2">   <StackPanel>    <StackPanel Orientation="Horizontal">     <TextBlock Text="abc" />     <TextBox Width="80"/>    </StackPanel>   </StackPanel>  </Label>  <StackPanel Orientation="Horizontal" Margin="0,30,0,0">   <Button Name="btnTestPopup1" Width="100" Height="30" Content="Bottom" Click="btnTestPopup1_Click" />   <Button Name="btnTestPopup2" Width="100" Height="30" Content="Top" Click="btnTestPopup2_Click" />   <Button Name="btnTestPopup3" Width="100" Height="30" Content="Right" Click="btnTestPopup3_Click" />   <Button Name="btnTestPopup4" Width="100" Height="30" Content="Left" Click="btnTestPopup4_Click" />  </StackPanel>  <Popup Name="pop1" AllowsTransparency="True" StaysOpen="False" PopupAnimation="Slide" PlacementTarget="{Binding ElementName=btnTestPopup1}" Placement="Bottom" >   <Label Style="{StaticResource TopBubblePanel}" Tag="Top">    <StackPanel>     <StackPanel Orientation="Horizontal">      <TextBlock Text="abc" />      <TextBox Width="80" Name="txtTest1" />     </StackPanel>     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">      <Button Content="確定" Click="btnOK1_Click" Width="50" Height="25" Margin="5" />      <Button Content="取消" Click="btnCancel1_Click" Width="50" Height="25" Margin="5"/>     </StackPanel>    </StackPanel>   </Label>  </Popup>  <Popup Name="pop2" AllowsTransparency="True" StaysOpen="False" PopupAnimation="Fade" PlacementTarget="{Binding ElementName=btnTestPopup2}" Placement="Top" >   <Label Style="{StaticResource BottomBubblePanel}" Tag="Top">    <StackPanel>     <StackPanel Orientation="Horizontal">      <TextBlock Text="abc" />      <TextBox Width="80" Name="txtTest2" />     </StackPanel>     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">      <Button Content="確定" Click="btnOK2_Click" Width="50" Height="25" Margin="5"/>      <Button Content="取消" Click="btnCancel2_Click" Width="50" Height="25" Margin="5"/>     </StackPanel>    </StackPanel>   </Label>  </Popup>  <Popup Name="pop3" AllowsTransparency="True" StaysOpen="False" PopupAnimation="Scroll" PlacementTarget="{Binding ElementName=btnTestPopup3}" Placement="Right" >   <Label Style="{StaticResource LeftBubblePanel}" Tag="Top">    <StackPanel>     <StackPanel Orientation="Horizontal">      <TextBlock Text="abc" />      <TextBox Width="80" Name="txtTest3" />     </StackPanel>     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">      <Button Content="確定" Click="btnOK2_Click" Width="50" Height="25" Margin="5"/>      <Button Content="取消" Click="btnCancel3_Click" Width="50" Height="25" Margin="5"/>     </StackPanel>    </StackPanel>   </Label>  </Popup>  <Popup Name="pop4" AllowsTransparency="True" StaysOpen="False" PopupAnimation="None" PlacementTarget="{Binding ElementName=btnTestPopup4}" Placement="Left" >   <Label Style="{StaticResource RightBubblePanel}" Tag="Top">    <StackPanel>     <StackPanel Orientation="Horizontal">      <TextBlock Text="abc" />      <TextBox Width="80" Name="txtTest4" />     </StackPanel>     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">      <Button Content="確定" Click="btnOK4_Click" Width="50" Height="25" Margin="5"/>      <Button Content="取消" Click="btnCancel4_Click" Width="50" Height="25" Margin="5"/>     </StackPanel>    </StackPanel>   </Label>  </Popup> </StackPanel></Window>

后臺代碼,很簡單,就是控制pupup顯示或隱藏

private void btnTestPopup1_Click(object sender, RoutedEventArgs e)  {   pop1.IsOpen = true;  }  private void btnOK1_Click(object sender, RoutedEventArgs e)  {   pop1.IsOpen = false;  }  private void btnCancel1_Click(object sender, RoutedEventArgs e)  {   pop1.IsOpen = false;  }  private void btnTestPopup2_Click(object sender, RoutedEventArgs e)  {   pop2.IsOpen = true;  }  private void btnOK2_Click(object sender, RoutedEventArgs e)  {   pop2.IsOpen = false;  }  private void btnCancel2_Click(object sender, RoutedEventArgs e)  {   pop2.IsOpen = false;  }  private void btnTestPopup3_Click(object sender, RoutedEventArgs e)  {   pop3.IsOpen = true;  }  private void btnOK3_Click(object sender, RoutedEventArgs e)  {   pop3.IsOpen = false;  }  private void btnCancel3_Click(object sender, RoutedEventArgs e)  {   pop3.IsOpen = false;  }  private void btnTestPopup4_Click(object sender, RoutedEventArgs e)  {   pop4.IsOpen = true;  }  private void btnOK4_Click(object sender, RoutedEventArgs e)  {   pop4.IsOpen = false;  }  private void btnCancel4_Click(object sender, RoutedEventArgs e)  {   pop4.IsOpen = false;  }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到ASP.NET教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产免费一区二区三区最新不卡 | 黄色片在线观看网站 | 成人午夜激情视频 | 黄污在线观看 | 精品亚洲一区二区 | 毛片一级网站 | 日韩av片网站 | 国产欧美日韩在线不卡第一页 | 精品国产91久久久久久浪潮蜜月 | 91看片在线观看视频 | a黄色片 | 久啪视频 | 久草视频福利在线观看 | 成人性生活视频在线观看 | 在线a亚洲视频播放在线观看 | 欧美77 | 欧美日韩在线视频一区 | 欧美日韩高清一区 | 色97色| 国产精品一区99 | 免费观看9x视频网站在线观看 | 国产亚洲欧美日韩高清 | 国产精品久久久久久久亚洲按摩 | 可以看逼的视频 | 欧美三级美国一级 | 久草在线小说 | 久久久久久久久日本理论电影 | 羞羞的视频 | 成人在线视频一区 | 亚洲精品成人久久 | 久久久久久久久国产精品 | 海外中文字幕在线观看 | 国产91小视频在线观看 | 国产精品久久久乱弄 | 黄污在线看 | 日本s级毛片免费观看 | 中国hdxxxx护士爽在线观看 | 国产日产精品一区四区介绍 | 日本成人高清视频 | 国产精品成人免费一区久久羞羞 | 久久久中文 |