Click here to Skip to main content
15,911,531 members
Home / Discussions / WPF
   

WPF

 
QuestionGet Tab For Context Menu Pin
Kevin Marois26-Jan-24 18:35
professionalKevin Marois26-Jan-24 18:35 
I have a tab control, and I have a header template and style:
<!Tab Item Header Template>
<DataTemplate x:Key="CustomHeaderTemplate">

    <DockPanel LastChildFill="True">

        <TextBlock Text="{Binding FileName}"
                   VerticalAlignment="Center"
                   FontSize="14"/>

        <Button Command="{Binding DataContext.CloseTabCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                CommandParameter="{Binding}"
                VerticalAlignment="Center"
                Height="22"
                Width="22"
                Background="SteelBlue"
                Margin="3,0,0,0">

            <Path Data="M1,9 L9,1 M1,1 L9,9"
                  Stroke="White"
                  StrokeThickness="2" />

        </Button>

    </DockPanel>

</DataTemplate>

<!Tab Item Style>
<Style TargetType="TabItem">

    <Setter Property="ContextMenu">
        <Setter.Value>
            <ContextMenu DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}" >

                <MenuItem Header="Close Tab"
                          Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseTabCommand}"
                          CommandParameter="{Binding}"/>

                <MenuItem Header="Close All Tabs"
                          Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseAllTabsCommand}"
                          CommandParameter="{Binding}"/>

                <MenuItem Header="Close All But This"
                          Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseAllButThisTabCommand}"
                          CommandParameter="{Binding}"/>
            </ContextMenu>

        </Setter.Value>
    </Setter>

</Style>
The problem is that if I right-click a tab that is NOT selected, and choose one of the close options, the SELECTED tab is closed. How can I specify that correct tab item in the command?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

QuestionINotifyDataErrorInfo Question Pin
Kevin Marois2-Jan-24 17:07
professionalKevin Marois2-Jan-24 17:07 
QuestionWhen Are All DependencyProperties Set Pin
Kevin Marois28-Dec-23 21:12
professionalKevin Marois28-Dec-23 21:12 
AnswerRe: When Are All DependencyProperties Set Pin
#realJSOP9-Apr-24 1:30
professional#realJSOP9-Apr-24 1:30 
QuestionDataTemplate Problem Pin
Kevin Marois5-Dec-23 12:08
professionalKevin Marois5-Dec-23 12:08 
AnswerRe: DataTemplate Problem Pin
Richard Deeming5-Dec-23 22:03
mveRichard Deeming5-Dec-23 22:03 
AnswerDataGrid Event Not Firing Pin
Kevin Marois30-Nov-23 13:11
professionalKevin Marois30-Nov-23 13:11 
GeneralRe: DataGrid Event Not Firing Pin
Andre Oosthuizen1-Dec-23 22:42
mveAndre Oosthuizen1-Dec-23 22:42 
GeneralRe: DataGrid Event Not Firing Pin
Kevin Marois2-Dec-23 7:41
professionalKevin Marois2-Dec-23 7:41 
QuestionDataGrid Exception Pin
Kevin Marois28-Nov-23 11:36
professionalKevin Marois28-Nov-23 11:36 
AnswerRe: DataGrid Exception Pin
Richard Deeming28-Nov-23 22:30
mveRichard Deeming28-Nov-23 22:30 
GeneralRe: DataGrid Exception Pin
Kevin Marois29-Nov-23 7:12
professionalKevin Marois29-Nov-23 7:12 
GeneralRe: DataGrid Exception Pin
Kevin Marois29-Nov-23 8:13
professionalKevin Marois29-Nov-23 8:13 
GeneralRe: DataGrid Exception Pin
Richard Deeming29-Nov-23 22:22
mveRichard Deeming29-Nov-23 22:22 
GeneralRe: DataGrid Exception Pin
Kevin Marois30-Nov-23 6:46
professionalKevin Marois30-Nov-23 6:46 
QuestionCustom Control Style Question Revisited Pin
Kevin Marois30-Oct-23 9:14
professionalKevin Marois30-Oct-23 9:14 
AnswerRe: Custom Control Style Question Revisited Pin
Gerry Schmitz30-Oct-23 12:20
mveGerry Schmitz30-Oct-23 12:20 
GeneralRe: Custom Control Style Question Revisited Pin
Kevin Marois31-Oct-23 8:01
professionalKevin Marois31-Oct-23 8:01 
QuestionUI Validation Problem Pin
Kevin Marois10-Oct-23 13:10
professionalKevin Marois10-Oct-23 13:10 
AnswerRe: UI Validation Problem Pin
Richard Deeming10-Oct-23 22:13
mveRichard Deeming10-Oct-23 22:13 
GeneralRe: UI Validation Problem Pin
Kevin Marois12-Oct-23 7:25
professionalKevin Marois12-Oct-23 7:25 
GeneralRe: UI Validation Problem Pin
Richard Deeming12-Oct-23 21:34
mveRichard Deeming12-Oct-23 21:34 
AnswerRe: UI Validation Problem Pin
Gerry Schmitz12-Oct-23 8:52
mveGerry Schmitz12-Oct-23 8:52 
GeneralRe: UI Validation Problem Pin
Kevin Marois12-Oct-23 14:54
professionalKevin Marois12-Oct-23 14:54 
GeneralRe: UI Validation Problem Pin
Gerry Schmitz12-Oct-23 19:12
mveGerry Schmitz12-Oct-23 19:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.