Опубликован: 08.07.2011 | Доступ: свободный | Студентов: 1788 / 93 | Оценка: 4.15 / 4.08 | Длительность: 15:28:00
Дополнительный материал 2:

Коды и XAML описания документов

< Дополнительный материал 1 || Дополнительный материал 2: 123

Шаблон данных ListBoxItemPhotoDataTemplate

<DataTemplate x:Key="ListBoxItemPhotoDataTemplate">
    <Border
	Padding="10"
	Background="{StaticResource PhotoBGSolidBrush}" 
	CornerRadius="5">
        <Border
		BorderBrush="{StaticResource PhotoBorderSolidBrush}"
		BorderThickness="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Source="{Binding Path=Picture, Mode=OneWay, 
                    Converter={StaticResource ImageConverter}}" 
                       Height="87" Width="60" Margin="5" 
                       Name="Image" Stretch="Uniform"   />
                <StackPanel  Grid.Column="1" Orientation="Vertical">
                    <TextBlock Text="{Binding Path=EmployeeSurname}" Margin="5,5,5,5" />
                    <TextBlock Text="{Binding Path=EmployeeName}" Margin="5" />
                    <TextBlock Text="{Binding Path=EmployeePatronymic}" Margin="5" />
                </StackPanel>
            </Grid>
        </Border>
    </Border>
</DataTemplate>

XAML-разметка стиля ButtonStyle

<Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="Background" Value="#FF1F3B53"/>
    <Setter Property="Foreground" Value="#FF000000"/>
    <Setter Property="Padding" Value="3"/>
    <Setter Property="BorderThickness" Value="1"/>
    <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 -->
        </Setter.Value>
    </Setter>
</Style>

Шаблон ControlTemplate для Button

<ControlTemplate TargetType="Button">
    <Grid 
        Cursor="Hand">
        <VisualStateManager.VisualStateGroups>
        <!—Описание состояний и поведения в этих состояниях -->
        </VisualStateManager.VisualStateGroups>
        <Border x:Name="Background" CornerRadius="3" Background="White" 
             BorderThickness="{TemplateBinding BorderThickness}" 
             BorderBrush="{TemplateBinding BorderBrush}">
            <Grid Background="{TemplateBinding Background}"  Margin="1">
                <Border x:Name="BackgroundAnimation" Opacity="0" Background="#FF448DCA" />
                <Rectangle x:Name="BackgroundGradient" >
                  <Rectangle.Fill>
                     <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1">
                        <GradientStop Color="#FFFFFFFF" Offset="0" />
                        <GradientStop Color="#F9FFFFFF" Offset="0.375" />
                        <GradientStop Color="#E5FFFFFF" Offset="0.625" />
                        <GradientStop Color="#C6FFFFFF" Offset="1" />
                      </LinearGradientBrush>
                   </Rectangle.Fill>
               </Rectangle>
            </Grid>
        </Border>
        <ContentPresenter
              x:Name="contentPresenter"
              Content="{TemplateBinding Content}"
              ContentTemplate="{TemplateBinding ContentTemplate}"
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
              Margin="{TemplateBinding Padding}"/>
        <Rectangle x:Name="DisabledVisualElement" RadiusX="3" RadiusY="3"
                 Fill="#FF95A0A3" Opacity="0" IsHitTestVisible="false" />
        <Rectangle x:Name="FocusVisualElement" RadiusX="2" RadiusY="2"  Margin="1" 
                               Stroke="#FF6DBDD1" StrokeThickness="1" Opacity="0" 
					IsHitTestVisible="false" />
        <Rectangle x:Name="MouseOverVisualElement" RadiusX="3" RadiusY="3" 
Margin="1" Stroke="#FF346797" StrokeThickness="1" Opacity="1" IsHitTestVisible="false" />
     </Grid>
</ControlTemplate>

XAML-разметка стиля ButtonStyle

<Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="Background" Value="#FF1F3B53"/>
    <Setter Property="Foreground" Value="#FF000000"/>
    <Setter Property="Padding" Value="3"/>
    <Setter Property="BorderThickness" Value="1"/>
    <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="Button">
                <Grid 
                    Cursor="Hand">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <!--Изменение цвета рамки (бордюра) кнопки-->
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" 
                                      Storyboard.TargetName="BackgroundAnimation" 
                                      Storyboard.TargetProperty="Opacity" To="1"/>
                                     <!--Изменение цвета рамки (бордюра) кнопки-->
                                    <ColorAnimation Duration="0" 
                                     Storyboard.TargetName="Background" 
                                     Storyboard.TargetProperty=
                                    "(Border.Background).(SolidColorBrush.Color)" 
                                     To="#FF346797"/>
                                     <ColorAnimation Duration="0"
                                      Storyboard.TargetName="BackgroundGradient"
                                      Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" 
                                      To="#F2FFFFFF"/>
                                      <ColorAnimation Duration="0" 
                                        Storyboard.TargetName="BackgroundGradient" 
                                        Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" 
                                        To="#CCFFFFFF"/>
                                       <ColorAnimation Duration="0" 
                                         Storyboard.TargetName="BackgroundGradient" 
                                         Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" 
                                         To="#7FFFFFFF"/>
                                        <!--Изменение толщины рамки кнопки-->
                                       <DoubleAnimation Duration="0"
                                          Storyboard.TargetName="MouseOverVisualElement" 
                                          Storyboard.TargetProperty="StrokeThickness"
                                          To="3"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" 
                                            Storyboard.TargetName="Background" 
                                            Storyboard.TargetProperty=
                                            "(Border.Background).(SolidColorBrush.Color)"
                                            To="#FF6DBDD1"/>
                                        <DoubleAnimation Duration="0" 
                                           Storyboard.TargetName="BackgroundAnimation" 
                                           Storyboard.TargetProperty="Opacity" 
                                           To="1"/>
                                        <ColorAnimation Duration="0" 
                                           Storyboard.TargetName="BackgroundGradient" 
                                           Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" 
                                           To="#D8FFFFFF"/>
                                        <ColorAnimation Duration="0" 
                                           Storyboard.TargetName="BackgroundGradient" 
                                           Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" 
                                           To="#C6FFFFFF"/>
                                        <ColorAnimation Duration="0"
                                            Storyboard.TargetName="BackgroundGradient" 
                                            Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" 
                                            To="#8CFFFFFF"/>
                                        <ColorAnimation Duration="0"
                                            Storyboard.TargetName="BackgroundGradient" 
                                            Storyboard.TargetProperty=
"(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" 
                                            To="#3FFFFFFF"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                       <DoubleAnimation Duration="0" 
                                          Storyboard.TargetName="DisabledVisualElement" 
                                          Storyboard.TargetProperty="Opacity" To=".55"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" 
                                            Storyboard.TargetName="FocusVisualElement" 
                                            Storyboard.TargetProperty="Opacity" 
                                            To="1"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Background" CornerRadius="3" Background="White" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                BorderBrush="{TemplateBinding BorderBrush}">
                            <Grid Background="{TemplateBinding Background}"  Margin="1">
                                <Border Opacity="0" x:Name="BackgroundAnimation"
                                                               Background="#FF448DCA" />
                                <Rectangle x:Name="BackgroundGradient" >
                                  <Rectangle.Fill>
                                     <LinearGradientBrush StartPoint=".7,0"
                                                                   EndPoint=".7, 1">
                                        <GradientStop Color="#FFFFFFFF" Offset="0" />
                                        <GradientStop Color="#F9FFFFFF" Offset="0.375" />
                                        <GradientStop Color="#E5FFFFFF" Offset="0.625" />
                                        <GradientStop Color="#C6FFFFFF" Offset="1" />
                                      </LinearGradientBrush>
                                   </Rectangle.Fill>
                               </Rectangle>
                            </Grid>
                        </Border>
                        <ContentPresenter
                              x:Name="contentPresenter"
                              Content="{TemplateBinding Content}"
                              ContentTemplate="{TemplateBinding ContentTemplate}"
                              VerticalAlignment=
                                     "{TemplateBinding VerticalContentAlignment}"
                              HorizontalAlignment=
                                      "{TemplateBinding HorizontalContentAlignment}"
                              Margin="{TemplateBinding Padding}"/>
                        <Rectangle x:Name="DisabledVisualElement" RadiusX="3" RadiusY="3"
                                 Fill="#FF95A0A3" Opacity="0" IsHitTestVisible="false" />
                        <Rectangle x:Name="FocusVisualElement" RadiusX="2" RadiusY="2" 
                                     Margin="1" Stroke="#FF6DBDD1" StrokeThickness="1"
                                     Opacity="0" IsHitTestVisible="false" />
                        <Rectangle x:Name="MouseOverVisualElement" RadiusX="3" 
                                     RadiusY="3" Margin="1" Stroke="#FF346797" 
                              StrokeThickness="1" Opacity="1" IsHitTestVisible="false" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
< Дополнительный материал 1 || Дополнительный материал 2: 123
Александр Петров
Александр Петров

При загрузке данных из БД возникает исключение InvalidOperationException с сообщением: Элемент коллекции должен быть пустым перед использованием ItemsSource. Знаю, что для заполнения DataGrid можно использовать коллекции Items или ItemsSource, но одновременно их использовать нельзя: если задано значение для свойства ItemsSource и в коде C# добавляется элемент в Items, возникает исключение. 
Вопрос, как отследить и отключить добавление элемента в Items?

Максим Спиридонов
Максим Спиридонов

В пятой лекции на второй странице в компиляторе выскакивает ошибка в строчке :

ObjectQuery<Employee> employees = DataEntitiesEmployee.Employees;

Ошибка CS0029

Не удается неявно преобразовать тип "System.Data.Entity.DbSet<WpfApplProject.Employee>" в "System.Data.Entity.Core.Objects.ObjectQuery<WpfApplProject.Employee>".

в using прописал все как положено, здесь похоже именно с преобразованием типов проблемы