InfoBadge.axaml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <ResourceDictionary xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:controls="clr-namespace:SukiUI.Controls"
  4. xmlns:converters="clr-namespace:SukiUI.Converters">
  5. <Design.PreviewWith>
  6. <StackPanel Width="300"
  7. Height="400"
  8. Margin="0,20,0,0"
  9. Spacing="20">
  10. <controls:InfoBadge Appearance="Information"
  11. CornerPosition="TopRight"
  12. Header="Info">
  13. <Button Content="Log In" />
  14. </controls:InfoBadge>
  15. <controls:InfoBadge Appearance="Warning"
  16. CornerPosition="TopLeft"
  17. Header="Warning">
  18. <Button />
  19. </controls:InfoBadge>
  20. <controls:InfoBadge Appearance="Success"
  21. CornerPosition="BottomRight"
  22. Header="Success">
  23. <Button />
  24. </controls:InfoBadge>
  25. <controls:InfoBadge Appearance="Error"
  26. CornerPosition="BottomLeft"
  27. Header="Error">
  28. <Button />
  29. </controls:InfoBadge>
  30. <controls:InfoBadge Appearance="Error"
  31. CornerPosition="TopRight"
  32. IsDot="True">
  33. <Button />
  34. </controls:InfoBadge>
  35. <controls:InfoBadge Appearance="Information"
  36. CornerPosition="TopRight"
  37. Header="100"
  38. Overflow="99">
  39. <Button />
  40. </controls:InfoBadge>
  41. </StackPanel>
  42. </Design.PreviewWith>
  43. <converters:InfoBadgeOverflowConverter x:Key="InfoBadgeContentConverter" />
  44. <ControlTheme x:Key="{x:Type controls:InfoBadge}" TargetType="{x:Type controls:InfoBadge}">
  45. <Setter Property="CornerRadius" Value="{DynamicResource MediumCornerRadius}" />
  46. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  47. <Setter Property="ClipToBounds" Value="False" />
  48. <Setter Property="HorizontalAlignment" Value="Center" />
  49. <Setter Property="VerticalAlignment" Value="Center" />
  50. <Setter Property="UseLayoutRounding" Value="False" />
  51. <Setter Property="Template">
  52. <ControlTemplate TargetType="{x:Type controls:InfoBadge}">
  53. <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  54. VerticalAlignment="{TemplateBinding VerticalAlignment}"
  55. ClipToBounds="False">
  56. <ContentPresenter Name="PART_ContentPresenter"
  57. HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  58. VerticalAlignment="{TemplateBinding VerticalAlignment}"
  59. Content="{TemplateBinding Content}"
  60. ContentTemplate="{TemplateBinding ContentTemplate}" />
  61. <Border Name="BadgeBorder"
  62. MinWidth="25"
  63. MinHeight="25"
  64. Padding="5,2,5,2"
  65. HorizontalAlignment="Right"
  66. VerticalAlignment="Top"
  67. Background="{TemplateBinding Background}"
  68. CornerRadius="{TemplateBinding CornerRadius}"
  69. IsVisible="{Binding !!Header, RelativeSource={RelativeSource TemplatedParent}}"
  70. UseLayoutRounding="False">
  71. <ContentPresenter Name="PART_HeaderPresenter"
  72. Margin="2"
  73. HorizontalAlignment="Center"
  74. VerticalAlignment="Center"
  75. Focusable="False"
  76. FontWeight="{DynamicResource DefaultDemiBold}"
  77. Foreground="White"
  78. IsTabStop="False">
  79. <ContentPresenter.Styles>
  80. <Style Selector="TextBlock">
  81. <Setter Property="FontSize" Value="13" />
  82. </Style>
  83. </ContentPresenter.Styles>
  84. <ContentPresenter.Content>
  85. <MultiBinding Converter="{StaticResource InfoBadgeContentConverter}">
  86. <Binding Path="Header" RelativeSource="{RelativeSource TemplatedParent}" />
  87. <Binding Path="Overflow" RelativeSource="{RelativeSource TemplatedParent}" />
  88. </MultiBinding>
  89. </ContentPresenter.Content>
  90. </ContentPresenter>
  91. </Border>
  92. </Grid>
  93. </ControlTemplate>
  94. </Setter>
  95. <Style Selector="^[IsDot=True]">
  96. <Setter Property="Template">
  97. <ControlTemplate TargetType="{x:Type controls:InfoBadge}">
  98. <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  99. VerticalAlignment="{TemplateBinding VerticalAlignment}"
  100. ClipToBounds="False">
  101. <ContentPresenter Name="PART_ContentPresenter"
  102. Margin="-1"
  103. HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  104. VerticalAlignment="{TemplateBinding VerticalAlignment}"
  105. Content="{TemplateBinding Content}"
  106. ContentTemplate="{TemplateBinding ContentTemplate}" />
  107. <Border Name="BadgeBorder"
  108. Width="14"
  109. Height="14"
  110. HorizontalAlignment="Right"
  111. VerticalAlignment="Top"
  112. Background="{TemplateBinding Background}"
  113. CornerRadius="{TemplateBinding CornerRadius}"
  114. IsVisible="{Binding !!Header, RelativeSource={RelativeSource TemplatedParent}}" />
  115. </Grid>
  116. </ControlTemplate>
  117. </Setter>
  118. </Style>
  119. <Style Selector="^[CornerPosition=TopLeft] /template/ Border#BadgeBorder">
  120. <Setter Property="HorizontalAlignment" Value="Left" />
  121. <Setter Property="VerticalAlignment" Value="Top" />
  122. </Style>
  123. <Style Selector="^[CornerPosition=TopRight] /template/ Border#BadgeBorder">
  124. <Setter Property="HorizontalAlignment" Value="Right" />
  125. <Setter Property="VerticalAlignment" Value="Top" />
  126. </Style>
  127. <Style Selector="^[CornerPosition=BottomLeft] /template/ Border#BadgeBorder">
  128. <Setter Property="HorizontalAlignment" Value="Left" />
  129. <Setter Property="VerticalAlignment" Value="Bottom" />
  130. </Style>
  131. <Style Selector="^[CornerPosition=BottomRight] /template/ Border#BadgeBorder">
  132. <Setter Property="HorizontalAlignment" Value="Right" />
  133. <Setter Property="VerticalAlignment" Value="Bottom" />
  134. </Style>
  135. </ControlTheme>
  136. </ResourceDictionary>