0
votes

I rolled my own "splitbutton" that consists of a button, expander and popup with 1-N more buttons. Now the buttons in popup come very thick border around them eventhough button's style has BorderThickness="0". So the border is probably set because buttons are in popup. My question is: How to override border so that all other Button style "properties" are not overridden?

    <Popup
        IsOpen="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type my:SplitButton}}, Path=IsExpanded}"
        PlacementTarget="{Binding ElementName=Button}"
        PopupAnimation="Fade"
        StaysOpen="False"
        >
        <Popup.Resources>
            <Style TargetType="Border">
                <Setter Property="BorderThickness" Value="0" />
            </Style>
        </Popup.Resources>
            <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type my:SplitButton}}, Path=ItemsSource}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                    <Button Content="{Binding Converter={ui:ConvertObjectToResource}}" Tag="{Binding}" Click="Control_Click" BorderThickness="0"
                            Width="{Binding ActualWidth, ElementName=WidthButton}">
                    </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
    </Popup>

EDIT: I can actually do like this:

        <Popup.Resources>
            <Style TargetType="Button">
                <Setter Property="BorderThickness" Value="0" />
            </Style>
        </Popup.Resources>

This unfortunately overrides button's all other style properties (like padding and background, foreground).

I can also do like this:

            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Content="{Binding Converter={ui:ConvertObjectToResource}}" Tag="{Binding}" Click="Control_Click"
                            Width="{Binding ActualWidth, ElementName=WidthButton}">
                        <Button.Style>
                            <Style TargetType="Button">
                                <Setter Property="BorderThickness" Value="0"></Setter>
                                <Setter Property="BorderBrush" Value="Transparent"></Setter>
                            </Style>
                        </Button.Style>
                    </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

but also that overrides button's style. If I try to tackle that by setting BasedOn="ButtonsNormalStyleHere" the borders come back again, i.e. BorderThickness and BorderBrush have no effect.

1
Running your code results in no borders around buttons for me. Probably you have some style interfering...3615
yes. of course I have a style. but I don't know which style. i just want to override it.char m
Well, that's totally another question. I cannot reproduce the problem you described. Add missing style to the question.3615
I don't understand what you mean. Maybe I asked the question wrongly, I updated the question. I am not gonna put Button's entire style in question because it is 350 lines and is totally irrelevant when I want to override BorderThickness/BorderBrush. Also in that style BorderThickness="0".char m
I mean a Minimal, Complete, and Verifiable example is missing. Without it I cannot reproduce problem locally so I may only guess what's happening. Btw, take a look at precedence order, it's related to overriding some property value.3615

1 Answers

1
votes

The "thick black border" is actually background of PopUp which is seen because of button margins -> I am complete idiot.