WPF 氣泡提示框的簡單實現


自己挖了一個大坑,,,然后苦逼的在碼代碼重寫樣式! 廢話不多說

直接上代碼

1 <TextBox Name="account" GotFocus="account_GotFocus" LostFocus="account_LostFocus" Style="{StaticResource LabelTextBox}" xl:ControlAttachProperty.Label="用戶名:"  Foreground="Black" Margin="10,10,273,271" Width="Auto" />

先在前台創建一個TextBox,然后各種附加的屬性加上去:如圖所示 

1 <Popup Name="pop3" AllowsTransparency="True" StaysOpen="True" PopupAnimation="Fade" IsOpen="False"  PlacementTarget="{Binding ElementName=account}" Placement="Right" >
2       <Label Style="{StaticResource tipLable}">
3               <StackPanel Orientation="Horizontal">
4                    <Label Content="請輸入用戶名"/>
5               </StackPanel>
6         </Label>
7  </Popup>

 

效果圖:

 

樣式代碼:

 1    <Style TargetType="Label" x:Key="tipLable">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type Label}">
 5                     <Grid>
 6                         <Border CornerRadius="4" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top" Margin="8.5,0,0,0" Background="Yellow" HorizontalAlignment="Left" Padding="5">
 7                             <ContentPresenter />
 8                         </Border>
 9                         <Canvas Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10,0,0" Background="Transparent">
10                             <Path Stroke="Black" StrokeThickness="0.5" Fill="Yellow">
11                                 <Path.Data>
12                                     <PathGeometry Figures="M 10,0 L 10,0,0,5  L 0,5,10,10"/>
13                                 </Path.Data>
14                             </Path>
15                         </Canvas>
16                     </Grid>
17                 </ControlTemplate>
18             </Setter.Value>
19         </Setter>
20     </Style>

本文原創出處:http://www.cnblogs.com/PettyHandSome/

歡迎各位轉載,但是未經作者本人同意,轉載文章之后必須在文章頁面明顯位置給出作者和原文連接,否則保留追究法律責任的權利


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM