2016-10-19 10 views
-1

나는 하나의 Window.xaml이있는 WPF 응용 프로그램에서 데이터베이스 (MSSQL 2008R2)에서 채워진 dataGrid를 사용하고 있는데, 그 데이터 그리드에서 주문을로드하고 있습니다. 내 데이터베이스에서.데이터베이스 개체 값에서 TextBlock 텍스트 값을 추가하는 방법

numberOfOrder로 주문을 그룹화하고, 동시에 주문을 많이 할 경우를 대비하여 주문을 확장하거나 축소 할 수도 있습니다.

어쨌든, 내 확장기 내부에 textBlock이있는 DockPanel이 있습니다. 데이터베이스의 각 주문 번호를 표시하기 위해 textBlock을 사용했지만 어떻게 데이터베이스에서 textBlock으로 다른 것을 표시 할 수 있을지 궁금합니다 (예를 들어 데이터베이스에 주문을 삽입 할 때 DateTime을 표시하고 싶습니다.이 속성은 allready입니다.) 지금까지했던 것처럼 numberOfOrder 대신 다른 것을 표시 할 수 있도록 모든 항목을 Number of Order로 그룹화하십시오.

enter image description here

주문 번호 : 여기

가 지금의 모습의 사진입니다 # 1 < - 나는 TextBlock에이를 표시하고있어 1 내 데이터베이스에서 numberOfOrder입니다. 나는 어쩌면 또는 어떤 날짜 시간을 표시 할 것이라고 말했다으로

<TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Number of Order:# {0}}" /> 

는 그리고 제가 여기서 뭘하고 싶은 것은, 대신 주문 번호의 다른 뭔가를 표시하는 것입니다, 그래서 나는 다음과 같이 할 것 :

XAML : (TextBlock이 여기에 중요)

,536 여기 enter image description here

는 전체 코드입니다

<DataGrid.GroupStyle> 
     <!-- Style for groups at top level. --> 
     <GroupStyle> 
      <GroupStyle.ContainerStyle> 
       <Style TargetType="{x:Type GroupItem}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="{x:Type GroupItem}"> 
           <Expander IsExpanded="True" Background="Black" Opacity="0.7"> 
            <Expander.Header > 
             <DockPanel Height="50" Margin="0,0,0,0" Name="dockPanel" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=ActualWidth}"> 

              <Button>...</Button> 
              <Button>...</Button> 

              <TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Number of Order:# {0}}" /> 

              </DockPanel> 
            </Expander.Header> 
            <Expander.Content> 
             <ItemsPresenter /> 
            </Expander.Content> 
           </Expander> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </GroupStyle.ContainerStyle> 
     </GroupStyle> 
    </DataGrid.GroupStyle> 

데이터 그리드 채우기 위해 사용된다 MY CLASS :

I 필링 AM 데이터 그리드 BEHIND
public class OrderLocal 
{ 
    public string Title   { get; set; } 
    public int Quantity   { get; set; } 
    public int NumberOfOrder  { get; set; } 
    public DateTime DateOfInput { get; set; } 

} 

CODE 모든 ORDERS :

public MainWindow() 
{ 

     InitializeComponent(); 
     this.WindowStartupLocation = WindowStartupLocation.CenterScreen; 
     this.WindowState = WindowState.Maximized; 

     var ordersList = OrdersController.localOrders(); 
     collectionViewSource.Source = ordersList; 

     collectionViewSource.GroupDescriptions.Add(new PropertyGroupDescription("NumberOfOrder")); 
     DataContext = collectionViewSource; 


} 

답변

0

은 어쩌면 당신은 또 다른 TextBlock에 넣을 수 있습니다 DockPanel에?

<DockPanel> 
    <Button DockPanel.Dock="Right"/> 
    <Button DockPanel.Dock="Right"/> 
    <TextBlock Text=""/> 
    <TextBlock Text"whatever you wan"/> 
    <TextBlock Text="{Binding Items, Converter={StaticResource ItemsConverter},StringFormat=\{0:d\}}"/> 
</DockPanel> 

컨버터 : 그것 뿐이다

public class ItemsConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     ReadOnlyObservableCollection<object> items = value as ReadOnlyObservableCollection<object>; 
     if (items == null) throw new ArgumentNullException(nameof(items)); 

     DateTime latestOrderDate = items.Max(x => x.OrderDate); 
     return latestOrderDate; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

. 다른 변환하면 항목에서 다른 값을 얻을 수 있습니다.

감사

스테 펜