<UserControl x:Class="TradeBlotter.Views.ETFHoldingView"
             xmlns:vw="clr-namespace:TradeBlotter.Views"	
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:dc="clr-namespace:TradeBlotter.UIUtils"
						 xmlns:local="clr-namespace:TradeBlotter.UIUtils"						 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
  <UserControl.Resources>
    <CollectionViewSource
      x:Key="ETFHoldings" 
      Source="{Binding Path=AllETFHoldings}"
      >
    </CollectionViewSource>
  </UserControl.Resources>
  <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="Loading ETF Holdings...">
  <Grid  Background="LightGray">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="6" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
          <RowDefinition Height="30" />
          <RowDefinition Height="3" />
          <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Label Grid.Row="0" Grid.Column="2" FontFamily="Arial" Content="{Binding Path=Title}" HorizontalAlignment="Center" FontSize="20"></Label>
    <StackPanel Orientation="Vertical" Grid.Row="2" Grid.Column="0">
      <Label Content="ETFSymbol" HorizontalAlignment="Center"></Label>
      <ComboBox ItemsSource="{Binding Path=ETFSymbols, Mode=OneTime}" SelectedItem="{Binding Path=SelectedSymbol, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
				<ComboBox.ItemsPanel>
					<ItemsPanelTemplate>
						<VirtualizingStackPanel/>
					</ItemsPanelTemplate>
				</ComboBox.ItemsPanel>				
			</ComboBox>
      <Label Content="Search For..." HorizontalAlignment="Center" Target="{Binding ElementName=searchTypeLbl}" ></Label>
      <TextBox Text="{Binding Path=SearchValue, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="False" IsReadOnly="False" />
      <RadioButton Content="Search Symbol" IsChecked="{Binding Path=IsSearchSymbolChecked}"></RadioButton>
      <RadioButton Content="Search Text" IsChecked="{Binding Path=IsSearchTextChecked}"></RadioButton>
      <Button Content="Search" Command="{Binding Path=SearchCommand}"></Button>
    </StackPanel>
    <DockPanel Grid.Row="2" Grid.Column="2" >
				<telerik:RadGridView AlternationCount="2" SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" ItemsSource="{Binding Path=AllETFHoldings, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" >
    <telerik:RadContextMenu.ContextMenu>
      <telerik:RadContextMenu x:Name="GridContextMenu" StaysOpen="False" ItemsSource="{Binding MenuItems}">
        <telerik:RadContextMenu.ItemContainerStyle>
            <Style TargetType="telerik:RadMenuItem">
                <Setter Property="Header" Value="{Binding Text}" />
                <Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
                <Setter Property="StaysOpenOnClick" Value="False" />
            </Style>
        </telerik:RadContextMenu.ItemContainerStyle>
      </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
      <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="ETFSymbol"  DataMemberBinding="{Binding Path=ETFHoldingSymbol}" >
          <telerik:GridViewColumn.ToolTipTemplate>
            <DataTemplate >
              <StackPanel Orientation="Horizontal" >
                <TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:ETFHoldingView}},Path=DataContext.ETFSymbolDescription}"/>
              </StackPanel>
            </DataTemplate>
          </telerik:GridViewColumn.ToolTipTemplate>
      </telerik:GridViewDataColumn>
      <telerik:GridViewDataColumn Header="Symbol"  DataMemberBinding="{Binding Path=HoldingSymbol}" >
          <telerik:GridViewColumn.ToolTipTemplate>
            <DataTemplate >
              <StackPanel Orientation="Horizontal" >
                <TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:ETFHoldingView}},Path=DataContext.HoldingSymbolDescription}"/>
              </StackPanel>
            </DataTemplate>
          </telerik:GridViewColumn.ToolTipTemplate>
      </telerik:GridViewDataColumn>
      <telerik:GridViewDataColumn Header="Share Class" DataMemberBinding="{Binding Path=HoldingSymbolShareClass}" />
      <telerik:GridViewDataColumn Header="Company" DataMemberBinding="{Binding Path=HoldingCompanyName}" />
      <telerik:GridViewDataColumn Header="Percent of Assets" DataMemberBinding="{Binding Path=PercentOfAssets}" >
				<telerik:GridViewDataColumn.AggregateFunctions>
					<local:ETFHoldingsSumFunctionPercentOfAssets />
				</telerik:GridViewDataColumn.AggregateFunctions>
			</telerik:GridViewDataColumn>
		  </telerik:RadGridView.Columns>
    </telerik:RadGridView>
  </DockPanel>
 </Grid>
 </wpfx:BusyIndicator>
</UserControl>
