漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

<Window x:Class="WPFDemo.CommentList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:WPFDemo"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Loaded="Window_Load"
    Title="RiskList" Height="512" Width="778">
    <Window.Resources>
       
        <ObjectDataProvider x:Key="getData" ObjectType="{x:Type c:GetCommentData}" MethodName="GetData">
            <ObjectDataProvider.MethodParameters>
                <sys:Int32>0</sys:Int32>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
       
        <Style x:Key="GridStyle" TargetType="{x:Type ListViewItem}">
            <Style.Resources>
                <c:AlternateListViewColor x:Key="myConverter"></c:AlternateListViewColor>
            </Style.Resources>        
            <Setter Property="Background">
                <Setter.Value>
                    <Binding RelativeSource="{RelativeSource Self}" Converter="{StaticResource myConverter}"></Binding>
                </Setter.Value>
            </Setter>       
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="BorderBrush" Value="Red"></Setter>
            <Setter Property="Padding" Value="0"></Setter>   
        </Style>

    </Window.Resources>
    <StackPanel Orientation="Vertical" Margin="0" HorizontalAlignment="Center">
        <StackPanel Width="500" Orientation="Horizontal" Margin="0 0 0 0" >
            <Button Content="Add" HorizontalAlignment="Center" Click="Add_Click" Width="150" ></Button>
            <Button Content="Delete" HorizontalAlignment="Center"  Width="150" ></Button>
        </StackPanel>
       
        <Line Margin="40 0 0 0" Width="500" Stroke="Bisque" StrokeThickness="1" X2="200"></Line>
        <Grid Margin="80 0 0 0" Height="auto" >
            <Grid.RowDefinitions>
                <RowDefinition Height="5*"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
        </Grid>
        <ListView Name="MyListView" Margin="0 0 0 0" Grid.Row="0" Grid.Column="0" Width="500" DataContext="{StaticResource getData}" ItemsSource="{Binding}" ItemContainerStyle="{StaticResource GridStyle}" >
          
            <ListView.View>
                <GridView AllowsColumnReorder="True" x:Name="gridComment" ColumnHeaderToolTip="Comment Information">
                    <GridViewColumn x:Name="first">
                        <GridViewColumnHeader>
                            <CheckBox x:Name="ckbAll"></CheckBox>
                        </GridViewColumnHeader>
                    </GridViewColumn>
                    <GridViewColumn Header="Comment">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Comment}" ToolTip="{Binding CommentToolTip}" TextAlignment="Right">
                                    <TextBlock.ContextMenu>
                                        <ContextMenu>
                                            <MenuItem Header="View Comment" Click="View_Click"></MenuItem>
                                            <MenuItem Header="Add Comment" Click="AddComment_Click"></MenuItem>
                                        </ContextMenu>
                                    </TextBlock.ContextMenu>
                                </TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=CrateDate}" Header="CreateDate" Width="100"></GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </StackPanel>
</Window>

  protected void Window_Load(object sender, RoutedEventArgs e)
        {
            ObjectDataProvider provider = (ObjectDataProvider)(this.FindResource("getData"));
            provider.MethodParameters[0] = 8;

            DataTemplate dt = new DataTemplate();
            FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
            fef.AddHandler(CheckBox.CheckedEvent, System.Delegate.CreateDelegate(typeof(RoutedEventHandler), this, "checkBox1_Checked"));
            fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
            Binding binding = new Binding();
            binding.Path = new PropertyPath("Comment");
            fef.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            fef.SetBinding(CheckBox.NameProperty, binding);
            dt.VisualTree = fef;
            first.CellTemplate = dt;
           //(this.MyListView.View as GridView).Columns.Insert(0, column);
        }
        /*http://www.xueit.com/html/2009-02/21_554_00.html
           GridViewColumn column = new GridViewColumn();
            GridViewColumnHeader h = new GridViewColumnHeader();
            h.Content = "??????";
            h.Tag = "*******";
            column.Header = h;
            DataTemplate dt = new DataTemplate();
            FrameworkElementFactory fef = new FrameworkElementFactory(typeof(CheckBox));
            Binding binding = new Binding();
            binding.Path = new PropertyPath("MarketIndicator");
            fef.SetBinding(CheckBox.ContentProperty, binding);
            fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
            dt.VisualTree = fef;
            column.CellTemplate = dt;

            (this.lvExecutionTable.View as GridView).Columns.Add(column);
         */

      

        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(e.OriginalSource.ToString());
           
        }

        private void MyListView_Selected(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe = null;
         
        }

posted on 2009-08-03 18:13  javaca88  阅读(186)  评论(0编辑  收藏  举报