微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 查询目录页面

1,设置lisbBox的style

    <Style x:Key="ListBoxItemStyle1" targettype="ListBoxItem">
        <Setter Property="Padding" Value="3"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="TabNavigation" Value="Local"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate targettype="ListBoxItem">
                    <Grid Background="{TemplateBinding Background}">
                        <vsm:visualstatemanager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="normal"/>
                                <vsm:VisualState x:Name="MouSEOver"/>
                                <vsm:VisualState x:Name="disabled">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity">
                                            <SplineDoubleKeyFrame KeyTime="0" Value=".55"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="SelectionStates">
                                <vsm:VisualState x:Name="Unselected"/>
                                <vsm:VisualState x:Name="Selected"/>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="Focusstates">
                                <vsm:VisualState x:Name="Focused"/>
                                <vsm:VisualState x:Name="Unfocused"/>
                            </vsm:VisualStateGroup>
                        </vsm:visualstatemanager.VisualStateGroups>
                        <Rectangle x:Name="fillColor" IsHitTestVisible="False" Opacity="0" Fill="#FFBADDE9" RadiusX="1" RadiusY="1"/>
                        <Rectangle x:Name="fillColor2" IsHitTestVisible="False" Opacity="0" Fill="#FFBADDE9" RadiusX="1" RadiusY="1"/>
                        <ContentPresenter HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" RenderTransformOrigin="0.5,0.5">
                            <ContentPresenter.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </ContentPresenter.RenderTransform>
                        </ContentPresenter>
                        <Rectangle x:Name="FocusVisualElement" Visibility="Collapsed" stroke="#FF6DBDD1" strokeThickness="1" RadiusX="1" RadiusY="1"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ContentListBoxStyle" targettype="ListBox">
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Background" Value="#FFFFFFFF"/>
        <Setter Property="Foreground" Value="#FF000000"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="TabNavigation" Value="Once"/>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9" Offset="0"/>
                    <GradientStop Color="#FF8399A9" Offset="0.375"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate targettype="ListBox">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
                        <ScrollViewer x:Name="ScrollViewer" Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" Padding="{TemplateBinding Padding}">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemStyle1}"/>
    </Style>

2,添加页面文件

<UserControl x:Class="Platform.Module.IndustryInfo.IndustryInfoEntryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.domainservices"
    xmlns:ds="clr-namespace:Platform.Web.Services;assembly=Platform.Infrastructure"
    mc:Ignorable="d">

    <Grid x:Name="LayoutRoot" Background="White">
        <ListBox ItemsSource="{Binding}" Margin="30,5" Style="{StaticResource ContentListBoxStyle}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Width="320" Height="240" Margin="30,10">
                        <Grid.RowDeFinitions>
                            <RowDeFinition Height="Auto"/>
                            <RowDeFinition/>
                        </Grid.RowDeFinitions>
                        <Border Style="{StaticResource HeaderedBorderStyle}">
                            <Grid>
                                <Grid.ColumnDeFinitions>
                                    <ColumnDeFinition Width="0.5*"/>
                                    <ColumnDeFinition Width="0.5*"/>
                                </Grid.ColumnDeFinitions>
                                <TextBlock Style="{StaticResource HeaderedTextBlockStyle}"  VerticalAlignment="Center" Text="{Binding}"/>
                                <HyperlinkButton x:Name="IndustryQueryHyperlink" Grid.Column="1" Content=">>>>"
                                                 HorizontalAlignment="Right" VerticalAlignment="Stretch" Margin="10,0"
                                                 VerticalContentAlignment="Stretch" Click="IndustryQueryHyperlink_Click"/>
                            </Grid>
                        </Border>
                        <riaControls:DomainDataSource x:Name="DomainData" QueryName="GetT_Bas_EnterListByCategory" AutoLoad="True">
                            <riaControls:DomainDataSource.DomainContext>
                                <ds:EmphasesCompanyDomainContext/>
                            </riaControls:DomainDataSource.DomainContext>
                            <riaControls:DomainDataSource.QueryParameters>
                                <riaControls:Parameter ParameterName="category" Value="{Binding}"/>
                            </riaControls:DomainDataSource.QueryParameters>
                        </riaControls:DomainDataSource>
                        <ListBox Grid.Row="1" Margin="10,5" ItemsSource="{Binding Data,ElementName=DomainData}"
                                 Style="{StaticResource ContentListBoxStyle}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Height="30">
                                        <HyperlinkButton x:Name="IndustryDetailHyperlink" Content="{Binding entername}"
                                                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"
                                                         Click="IndustryDetailHyperlink_Click"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <controls:WrapPanel Orientation="Horizontal" Width="800" HorizontalAlignment="Left"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</UserControl>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Platform.Web.Services;
using Platform.Web.DataBase;
using Platform.Module.IndustryInfo.Views;
using System.Collections.ObjectModel;
using Platform.Infrastructure;

namespace Platform.Module.IndustryInfo
{
    public partial class IndustryInfoEntryView : UserControl,INavigationAware
    {
        private IRegionManager regionManager = null;
        private DomainDataSource dataSource = new DomainDataSource();
        private EmphasesCompanyDomainContext context = new EmphasesCompanyDomainContext();
        private ObservableCollection<string> categories = new ObservableCollection<string>();

        public IndustryInfoEntryView(IRegionManager regionManager)
        {
            InitializeComponent();

            this.regionManager = regionManager;
            dataSource.DomainContext = context;
            dataSource.QueryName = "GetT_Bas_EnterList";
            dataSource.LoadedData += new EventHandler<LoadedDataEventArgs>(dataSource_LoadedData);
        }

        void dataSource_LoadedData(object sender,LoadedDataEventArgs e)
        {
            categories.Clear();
            foreach (var data in dataSource.Data)
            {
                T_Bas_EnterList enterList = data as T_Bas_EnterList;
                if (enterList != null && !categories.Contains(enterList.code_Trade))
                {
                    categories.Add(enterList.code_Trade);
                }
            }
            this.DataContext = categories;
        }

        bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            dataSource.Load();
        }

        private void IndustryDetailHyperlink_Click(object sender,RoutedEventArgs e)
        {
            regionManager.Regions[RegionNames.MainContentRegion].Context = (e.OriginalSource as FrameworkElement).DataContext;
            regionManager.RequestNavigate(RegionNames.MainContentRegion,MainContentRegionViewNames.IndustryInfoDetailsView);
        }

        private void IndustryQueryHyperlink_Click(object sender,RoutedEventArgs e)
        {

        }
    }
}

3,在domainservice中添加方法支持

        public IQueryable<T_Bas_EnterList> GetT_Bas_EnterListByCategory(string category)         {             return this.ObjectContext.T_Bas_EnterList                 .Where(e => e.code_Trade.Equals(category))                 .Take(5);         }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐