Silverlight の HTML の従来の Fieldset が見つからず、Web 上で解決策を見つけることができませんでした。ビルドするにはどうすればよいですか?
1570 次
2 に答える
1
建ててみようと思いました。
それはおそらくそれを解決するための最良の方法ではありませんが、うまくいきます.
ただし、簡単な解決策として、FontSize、Foreground、および凡例のタイトルを設定できます。
マークアップ:
<Controls:Fieldset BorderBrush="#FFcccccc" Legend="LegendHeader" LegendFontSize="14" LegendForeground="Green">
<Button Content="Button" />
</Controls:Fieldset>
コントロール スタイル:
<Style TargetType="Controls:Fieldset">
<Setter Property="Padding" Value="10"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="BorderBrush" Value="#FFcccccc"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="LegendFontSize" Value="14"/>
<Setter Property="LegendForeground" Value="Black"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:Fieldset">
<Grid x:Name="LayoutRoot" Margin="{TemplateBinding Margin}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1,1,0,0" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="5,0,0,0"/>
<Border Grid.Column="1" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"/>
<Border Grid.Column="3" BorderThickness="0,1,0,0" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"/>
<Border Grid.Column="4" BorderThickness="0,1,1,0" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="0,5,0,0"/>
<Border Grid.ColumnSpan="5" Grid.Row="1" BorderThickness="1,0,1,1" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="0,0,5,5"/>
<Border Background="{TemplateBinding Background}" Margin="0,1,0,0" Grid.Column="2"/>
<Grid Grid.Column="2" Margin="10,-30,10,-30">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{TemplateBinding LegendFontSize}" Foreground="{TemplateBinding LegendForeground}" Text="{TemplateBinding Legend}"/>
</Grid>
<Border Background="{TemplateBinding Background}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3"/>
<ContentPresenter
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.Row="1"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
そしてクラス:
Public Class Fieldset
Inherits ContentControl
Public Sub New()
End Sub
Public Shared ReadOnly LegendProperty As DependencyProperty = DependencyProperty.
Register("Legend", GetType(String), GetType(Fieldset), New PropertyMetadata(AddressOf OnLegendChanged))
Private Shared Sub OnLegendChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim fieldset = TryCast(d, Fieldset)
fieldset.Legend = e.NewValue.ToString()
End Sub
Public Property Legend As String
Get
Return Me.GetValue(LegendProperty).ToString()
End Get
Set(ByVal value As String)
MyBase.SetValue(LegendProperty, value)
End Set
End Property
Public Shared ReadOnly LegendFontSizeProperty As DependencyProperty = DependencyProperty.
Register("LegendFontSize", GetType(Double), GetType(Fieldset), New PropertyMetadata(AddressOf OnLegendFontSizeChanged))
Private Shared Sub OnLegendFontSizeChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim fieldset = TryCast(d, Fieldset)
fieldset.LegendFontSize = CDbl(e.NewValue)
End Sub
Public Property LegendFontSize As Double
Get
Return CDbl(Me.GetValue(LegendFontSizeProperty))
End Get
Set(ByVal value As Double)
MyBase.SetValue(LegendFontSizeProperty, value)
End Set
End Property
Public Shared ReadOnly LegendForegroundProperty As DependencyProperty = DependencyProperty.
Register("LegendForeground", GetType(SolidColorBrush), GetType(Fieldset), New PropertyMetadata(AddressOf OnLegendForegroundChanged))
Private Shared Sub OnLegendForegroundChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim fieldset = TryCast(d, Fieldset)
fieldset.LegendForeground = DirectCast(e.NewValue, SolidColorBrush)
End Sub
Public Property LegendForeground As SolidColorBrush
Get
Return DirectCast(Me.GetValue(LegendForegroundProperty), SolidColorBrush)
End Get
Set(ByVal value As SolidColorBrush)
MyBase.SetValue(LegendForegroundProperty, value)
End Set
End Property
End Class
VB.NET コードで申し訳ありません。
私が言ったように、おそらくもっと良い解決策がたくさんありますが、ここに行きます。
于 2010-11-05T10:11:38.970 に答える
0
私は2つのオプションを認識しています:
無料のサードパーティ製 Fieldset コントロールを使用してください:
http://www.vectorlight.net/silverlight/controls/fieldset.aspx
http://www.vectorlight.net/silverlight/controls/fieldset/reference.aspx追加のフォーム固有の機能を備えた DataForm の使用を検討してください:
http://www.silverlightshow.net/items/Creating-Rich-Data-Forms-in-Silverlight-3-Introduction.aspx
于 2010-11-05T11:40:05.593 に答える