사용자 지정 목록 상자를 만들고 부울을 기반으로 몇 가지 항목에 대해 마우스를 가리 키거나 마우스를 선택하지 못하게하려고합니다. 스타일 클래스를 사용하고 사용자 정의 목록 상자의 코드에서 스타일을 설정합니다. 내 코드는 다음과 같습니다 :CustomListbox에서 선택한 항목에 대해 마우스 가져 오기 및 선택 사용 안 함
public class DragDropListBox : ListBox
{
public DragDropListBox()
{
Style itemContainerStyle = new Style(typeof(ListBoxItem));
itemContainerStyle.Setters.Add(new EventSetter(ListBoxItem.DropEvent, new DragEventHandler(ListBoxItemDropHandler)));
this.ItemContainerStyle = itemContainerStyle;
}
}
지금 당장 나는 drop 이벤트에 대한 이벤트 설정기를 설정하고 올바르게 작동합니다. 플래그를 기반으로 항목에 마우스를 가져 가거나 마우스 선택 효과를 사용하지 않도록 스타일을 설정하려면 어떻게해야합니까? 내가 찾은 대부분의 코드는 XAML에있었습니다. 하지만 내 사용자 정의 목록 상자에 대한 코드가 필요합니다. 어떤 도움을 주시면 감사하겠습니다.
지금까지이 스타일은 나에게 있지만 작동 무엇 자사의 XAML에서 나는 그것이 C# 코드, 특별히 시각적 상태 및 스토리 보드 ..
<Style x:Key="ListBoxItemStyleTransparentSelect" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<EventSetter Event="Drop" Handler="listbox1_Drop"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="fillColor" IsHitTestVisible="True" Opacity="0" RadiusY="1" RadiusX="1"/>
<Rectangle x:Name="fillColor2" IsHitTestVisible="True" Opacity="0" RadiusY="1" RadiusX="1"/>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
<Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" StrokeThickness="1" Visibility="Collapsed"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
나는 그것을 안다. 편집 된 질문을 살펴보십시오. –