이미지처럼 작동하는 단추가있는 동적 그리드가 있습니다. 디자인 목적을 위해 나는 그 그림들 주위에 경계선을 가지길 원한다.이미지 단추의 테두리
EmployeeButton employeeTile = new EmployeeButton(); // inherits from Button, nothing fancy, just added three attributes for future use
Style style = this.FindResource("NoChromeButton") as Style;
employeeTile.Style = style;
// make it square (like a tile)
employeeTile.Width = Properties.Settings.Default.tileWidthInPx;
employeeTile.Height = employeeTile.Width;
// Create Background
var brush = new ImageBrush();
brush.ImageSource = item.Source; // item is an Image (part of a foreach)
employeeTile.Background = brush;
// set the margin between tiles
int margin = Properties.Settings.Default.tileMargin;
employeeTile.Margin = new Thickness(margin, margin, margin, 0);
// draw a border if the user wants to
if (Properties.Settings.Default.tileBorderThickness > 0)
{
employeeTile.BorderBrush = Brushes.Black;
employeeTile.BorderThickness = new Thickness(Properties.Settings.Default.tileBorderThickness);
}
가독성을 위해 나는 내 질문에 관련되지 않은 일부 라인을 삭제 :
그래서 여기에 코드입니다.
다음은 위에 사용 된 스타일의 xaml 코드입니다. 나는 전혀 국경 바로 클릭 할 수있는 이미지가 없다, 그것은 어딘가에 유래에 내가 아무리 두께를 설정하는 방법 큰
<Style x:Key="NoChromeButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
<Setter Property="Opacity" TargetName="Chrome" Value="0.5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
: 생각을 찾을 수 없습니다.
버튼에 테두리 속성이 있습니까? 그렇지 않으면 테두리 요소를 만들고 그 크기/모양을 설정하고 해당 테두리 요소 안에 이미지/단추를 중첩 시키려고합니다. – CalebB
내가 볼 수있는 유일한 속성은 BorderBrush와 BorderThickness입니다. 왜 내가 설정하려고했는지. 동적으로이 버튼을 생성하기 때문에 먼저 테두리를 만든 다음 버튼을 자식으로 추가해야합니까? 다음과 같은 것 (짧은) : border border = new border(); border.children.add (button); ? @CalebB – zuckerthoben
그래, 둘 다 "테두리"속성이므로 경계선이 있습니다. 테두리 브러시는 어디에 설정되어 있습니까? 'border'속성 ">"border inside inside " – CalebB