Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > WPF и Silverlight > ListBox и ContextMenu


Автор: IlyaIlin 1.11.2009, 10:50
Код

<DataTemplate x:Key="DataTemplateListAccounts">
        <Grid ContextMenu="{Binding Path=ContextMenu}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Rectangle Fill="Red" Grid.Column="0" />
        <TextBlock Text="{Binding Path=ICQAccount.Login}"  Grid.Column="1" Foreground="White" />
    </Grid>
</DataTemplate>

Коллеги, буду очень благодарен, если кто нибудь может объяснить путь решения проблемы. Grid в ListBox не растягивается по ширине, а только "обтягивает" Rectangle и TextBox, соответственно ContextMenu работает только тогда когда кликаешь по тексту. 

Автор: math64 1.11.2009, 11:23
Для ListView так:
Код

                <ListView.ItemContainerStyle>
                    <Style TargetType ="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                    </Style>
                </ListView.ItemContainerStyle>


(Как для ListBox сейчас посмотреть не могу - на компьютере нет VS)

Автор: IlyaIlin 1.11.2009, 13:33
math64 спасибо, вы меня выручили. Я думал что-то в DataTemplate нужно сделать. 
На ListBox, работает в точности так-же, так: (Ваш код).Replace("View", "Box");
 smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)