0

This is my code for generating the gridview

        User u1 = new User();
        User u2 = new User();

        for (int i = 0; i < files.Count; i++)
        {
            u1.Files = files[i];
            items.Add(u1);
        }

        for (int i = 0; i < sharedFiles.Count; i++)
        {
            u2.Files += sharedFiles[i];
            items.Add(u2);
        }
        gridview1.ItemsSource = items;
    }

    public class User
    {
        public string Files { get; set; }
    }

This is my xaml page

 <ListView.View>
            <GridView >
                <GridView.Columns>

                    <GridViewColumn Width="250" DisplayMemberBinding="{Binding Files}" ></GridViewColumn>

                    <GridViewColumn >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Download" Click="fileDownloadClick" CommandParameter="{Binding Files}"></Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Share"  Click="fileShareClick"  CommandParameter="{Binding Files}" ></Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                </GridView.Columns>

            </GridView>
 </ListView.View>  

I would like to know if its possible to only allow my Share buttons disabled in my 2nd for loop (u2) while my Share buttons in (u1) is still enabled. Currently both are enabled. I am currently using this to retrieve values for particular role

 private void fileShareClick(object sender, RoutedEventArgs e)
    {
        object share = ((Button)sender).CommandParameter;
    }
4

1 回答 1

0

在您想要的 Button 上创建一个 DataTrigger。并将其与表示布尔类型值的属性绑定。像 IsShareAllowed。

尝试这样的事情。

var procs = (from p in System.Diagnostics.Process.GetProcesses()

                     select new
                     {
                         Name = p.ProcessName,

                         IsShareAllowed = Convert.ToBoolean(r.Next(-1, 1))
                     }).ToList(); ;

        list.ItemsSource = procs;

Xaml

 <ListView Name="list" Grid.Row="4">
            <ListView.View>
                <GridView >
                    <GridView.Columns>

                        <GridViewColumn Width="250" DisplayMemberBinding="{Binding Name}" />

                        <GridViewColumn >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="Download" Click="fileDownloadClick" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="Share"  Click="fileShareClick"  >
                                        <Button.Style>
                                            <Style TargetType="Button">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsShareAllowed}" Value="false">
                                                        <Setter Property="IsEnabled" Value="false"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>                                        
                                    </Button>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                    </GridView.Columns>

                </GridView>
            </ListView.View>
        </ListView>
于 2013-07-16T10:58:48.517 回答