forked from microsoft/WPF-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CustomComboBox project to the Sample Applications (microsoft#52)
- Loading branch information
Showing
16 changed files
with
977 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace CustomComboBox | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Sample Applications/CustomComboBox/Converters/StringToStringAndColorConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Data; | ||
|
||
namespace CustomComboBox.Converters | ||
{ | ||
class StringToStringAndColorConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
switch (parameter) | ||
{ | ||
case "text": | ||
return (value == null) ? "No movie selected!" : "Streaming.. "; | ||
case "color": | ||
return (value == null) ? "Red" : "Green"; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
Sample Applications/CustomComboBox/CustomComboBox.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{9E3EECAF-86CF-45CB-8ABB-01A850A308F0}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>CustomComboBox</RootNamespace> | ||
<AssemblyName>CustomComboBox</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<WarningLevel>4</WarningLevel> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xaml"> | ||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="WindowsBase" /> | ||
<Reference Include="PresentationCore" /> | ||
<Reference Include="PresentationFramework" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ApplicationDefinition Include="App.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</ApplicationDefinition> | ||
<Page Include="MainWindow.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</Page> | ||
<Compile Include="App.xaml.cs"> | ||
<DependentUpon>App.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Converters\StringToStringAndColorConverter.cs" /> | ||
<Compile Include="DropList.cs" /> | ||
<Compile Include="MainWindow.xaml.cs"> | ||
<DependentUpon>MainWindow.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="MainWindowViewModel.cs" /> | ||
<Compile Include="Movie.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
|
||
namespace CustomComboBox | ||
{ | ||
class DropList : ContentControl | ||
{ | ||
public ICommand Command | ||
{ | ||
get { return (ICommand)GetValue(CommandProperty); } | ||
set { SetValue(CommandProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty CommandProperty = | ||
DependencyProperty.Register("Command", typeof(ICommand), typeof(DropList), new PropertyMetadata(null)); | ||
|
||
public object CommandParameter | ||
{ | ||
get { return GetValue(CommandParameterProperty); } | ||
set { SetValue(CommandParameterProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty CommandParameterProperty = | ||
DependencyProperty.Register("CommandParameter", typeof(object), typeof(DropList), new PropertyMetadata(null)); | ||
|
||
public string SubTitle | ||
{ | ||
get { return (string)GetValue(SubTitleProperty); } | ||
set { SetValue(SubTitleProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty SubTitleProperty = | ||
DependencyProperty.Register("SubTitle", typeof(string), typeof(DropList)); | ||
|
||
public string DynamicText | ||
{ | ||
get { return (string)GetValue(DynamicTextProperty); } | ||
set { SetValue(DynamicTextProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty DynamicTextProperty = | ||
DependencyProperty.Register("DynamicText", typeof(string), typeof(DropList)); | ||
|
||
|
||
public IEnumerable<object> ItemsSource | ||
{ | ||
get { return (IEnumerable<object>)GetValue(ItemsSourceProperty); } | ||
set { SetValue(ItemsSourceProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty ItemsSourceProperty = | ||
DependencyProperty.Register("ItemsSource", typeof(IEnumerable<object>), typeof(DropList)); | ||
|
||
|
||
public string DisplayMemberPath | ||
{ | ||
get { return (string)GetValue(DisplayMemberPathProperty); } | ||
set { SetValue(DisplayMemberPathProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty DisplayMemberPathProperty = | ||
DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(DropList), new PropertyMetadata(null)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Window x:Class="CustomComboBox.MainWindow" | ||
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:local="clr-namespace:CustomComboBox" | ||
xmlns:converters="clr-namespace:CustomComboBox.Converters" | ||
mc:Ignorable="d" WindowStartupLocation="CenterScreen" | ||
Title="MainWindow" Height="350" Width="525"> | ||
<Window.DataContext> | ||
<local:MainWindowViewModel/> | ||
</Window.DataContext> | ||
<Window.Resources> | ||
<converters:StringToStringAndColorConverter x:Key="stringConverter"/> | ||
</Window.Resources> | ||
<Grid> | ||
<local:DropList Content="Watch Now" SubTitle="Movie: " | ||
FontWeight="Bold" | ||
HorizontalAlignment="Center" VerticalAlignment="Top" | ||
Style="{StaticResource DropListStyle}" | ||
ItemsSource="{Binding Movies}" Command="{Binding OnWatchNow}" | ||
DisplayMemberPath="Title"/> | ||
|
||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"> | ||
<TextBlock FontWeight="Bold" HorizontalAlignment="Left" | ||
Text="{Binding SelectedMovie, Converter={StaticResource stringConverter}, ConverterParameter=text}" | ||
Foreground="{Binding SelectedMovie, Converter={StaticResource stringConverter}, ConverterParameter=color}"/> | ||
<TextBlock Text="{Binding SelectedMovie}" HorizontalAlignment="Center" /> | ||
|
||
</StackPanel> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace CustomComboBox | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Windows.Input; | ||
|
||
namespace CustomComboBox | ||
{ | ||
class MainWindowViewModel : INotifyPropertyChanged | ||
{ | ||
public MainWindowViewModel() | ||
{ | ||
Movies2 = new List<string> | ||
{ | ||
"Movie1", | ||
"Movie2", | ||
"Movie3", | ||
"Movie4", | ||
"Movie5", | ||
"Movie6" | ||
}; | ||
Movies = new List<Movie> | ||
{ | ||
new Movie{Id=1, Title="The Dark Knight" }, | ||
new Movie{Id=2, Title="The Big Lebowski" }, | ||
new Movie{Id=3, Title="The Shawshank Redemption" }, | ||
new Movie{Id=4, Title="Schindler's List" }, | ||
new Movie{Id=5, Title="Pulp Fiction" }, | ||
new Movie{Id=6, Title="Fight Club" } | ||
}; | ||
|
||
OnWatchNow = new WatchNowCommand(ShowMovie); | ||
} | ||
|
||
private void ShowMovie(object parameter) | ||
{ | ||
if (parameter != null) | ||
{ | ||
|
||
if (parameter is string s) | ||
SelectedMovie = s; | ||
else if (parameter is Movie m) | ||
SelectedMovie = m.Title; | ||
} | ||
} | ||
|
||
public List<Movie> Movies { get; set; } | ||
public List<string> Movies2 { get; set; } | ||
public event PropertyChangedEventHandler PropertyChanged = delegate { }; | ||
public ICommand OnWatchNow { get; set; } | ||
string selectedMovie; | ||
public string SelectedMovie | ||
{ | ||
get { return selectedMovie; } | ||
set | ||
{ | ||
selectedMovie = value; | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedMovie))); | ||
} | ||
} | ||
} | ||
|
||
public class WatchNowCommand : ICommand | ||
{ | ||
Action<object> _execute; | ||
public WatchNowCommand(Action<object> execute) | ||
{ | ||
_execute = execute; | ||
} | ||
public event EventHandler CanExecuteChanged; | ||
|
||
public bool CanExecute(object parameter) => true; | ||
|
||
public void Execute(object parameter) => | ||
_execute(parameter); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace CustomComboBox | ||
{ | ||
class Movie | ||
{ | ||
public string Title { get; set; } | ||
public int Id { get; set; } | ||
} | ||
} |
Oops, something went wrong.