Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LazyComboBox.WPF/LazyComboBox.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="GenderType.cs" />
<Compile Include="LookupContext.cs" />
<Compile Include="SelectedItemChangedEventArgs.cs" />
<Page Include="Themes\Dark.xaml">
<SubType>Designer</SubType>
Expand All @@ -73,7 +73,7 @@
<ItemGroup>
<Compile Include="DependencyObjectExtensions.cs" />
<Compile Include="LazyComboBox.cs" />
<Compile Include="LookupContext.cs" />
<Compile Include="LookupContextImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
6 changes: 3 additions & 3 deletions LazyComboBox.WPF/LazyComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LazyComboBox : Control, INotifyPropertyChanged

private ICollectionView _itemsView;

private LookupContext _lastContext;
private LookupContextImpl _lastContext;

private int _lastIdx = -1;

Expand Down Expand Up @@ -434,7 +434,7 @@ private IEnumerable<object> TryLocateCandidatesByText(string text)
}
}

private void ExecuteLookup(LookupContext ctx, bool async = true, bool selectFirstCandidate = false)
private void ExecuteLookup(LookupContextImpl ctx, bool async = true, bool selectFirstCandidate = false)
{
#if DEBUG
var source = new StackFrame(1).GetMethod().ToString();
Expand All @@ -449,7 +449,7 @@ private void ExecuteLookup(LookupContext ctx, bool async = true, bool selectFirs
_token = new CancellationTokenSource();

var input = _textBox?.Text;
ctx = ctx ?? new LookupContext(input, _token.Token, null, this);
ctx = ctx ?? new LookupContextImpl(input, _token.Token, null, this);

ListUpdating = true;
Action x = () =>
Expand Down
106 changes: 48 additions & 58 deletions LazyComboBox.WPF/LookupContext.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,54 @@
using System.Collections;
using System.Threading;

// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace uTILLIty.Controls.WPF.LazyComboBox
{
/// <summary>
/// The context passed to the <see cref="LazyComboBox.LookupAction" /> delegate, when the <see cref="LazyComboBox" />
/// needs to populate the popup-list
/// </summary>
public class LookupContext
{
internal LookupContext(string input, CancellationToken token, object tag, LazyComboBox cb)
{
SelectedItem = cb.SelectedItem;
Input = input;
CancellationToken = token;
Tag = tag;
}

/// <summary>
/// The currently <see cref="LazyComboBox.SelectedItem">selected item</see> of the <see cref="LazyComboBox" />
/// </summary>
public object SelectedItem { get; private set; }

/// <summary>
/// The user's input into the Textbox field of the <see cref="LazyComboBox" />
/// </summary>
public string Input { get; private set; }

/// <summary>
/// A <see cref="CancellationToken" /> to periodically check for cancellation, in case the user continued
/// to enter data and a new lookup-request needs to be started
/// </summary>
public CancellationToken CancellationToken { get; private set; }

/// <summary>
/// An arbitrary state-object which is passed on subsequent requests to <see cref="LazyComboBox.LookupAction" />, if the
/// <see cref="NextPageRequested" /> property is set to true
/// </summary>
public object Tag { get; set; }

/// <summary>
/// Requests the next page to be loaded, because the user has scrolled to the end of the current list and your
/// <see cref="LazyComboBox.LookupAction" /> has set <see cref="MoreDataAvailable" /> to true on the last run.
/// After loading the next page, you should add the newly loaded page to the end of the <see cref="LoadedList" />
/// </summary>
public bool NextPageRequested { get; internal set; }

/// <summary>
/// The list of records returned by the <see cref="LazyComboBox.LookupAction" /> delegate. The current list is also
/// pre-populated,
/// if <see cref="NextPageRequested" /> is set to true
/// </summary>
public IEnumerable LoadedList { get; set; }

/// <summary>
/// Set by the <see cref="LazyComboBox.LookupAction" /> delegate to indicate that more records are available
/// and can be requested for the current <see cref="Input" />
/// </summary>
public bool MoreDataAvailable { get; set; }
}
/// <summary>
/// The context passed to the <see cref="LazyComboBox.LookupAction" /> delegate, when the <see cref="LazyComboBox" />
/// needs to populate the popup-list
/// </summary>
public interface LookupContext
{
/// <summary>
/// A <see cref="CancellationToken" /> to periodically check for cancellation, in case the user continued
/// to enter data and a new lookup-request needs to be started
/// </summary>
CancellationToken CancellationToken { get; }

/// <summary>
/// The user's input into the Textbox field of the <see cref="LazyComboBox" />
/// </summary>
string Input { get; }

/// <summary>
/// The list of records returned by the <see cref="LazyComboBox.LookupAction" /> delegate. The current list is also
/// pre-populated,
/// if <see cref="NextPageRequested" /> is set to true
/// </summary>
IEnumerable LoadedList { get; set; }

/// <summary>
/// Set by the <see cref="LazyComboBox.LookupAction" /> delegate to indicate that more records are available
/// and can be requested for the current <see cref="Input" />
/// </summary>
bool MoreDataAvailable { get; set; }

/// <summary>
/// Requests the next page to be loaded, because the user has scrolled to the end of the current list and your
/// <see cref="LazyComboBox.LookupAction" /> has set <see cref="MoreDataAvailable" /> to true on the last run.
/// After loading the next page, you should add the newly loaded page to the end of the <see cref="LoadedList" />
/// </summary>
bool NextPageRequested { get; }

/// <summary>
/// The currently <see cref="LazyComboBox.SelectedItem">selected item</see> of the <see cref="LazyComboBox" />
/// </summary>
object SelectedItem { get; }

/// <summary>
/// An arbitrary state-object which is passed on subsequent requests to <see cref="LazyComboBox.LookupAction" />, if the
/// <see cref="NextPageRequested" /> property is set to true
/// </summary>
object Tag { get; set; }
}
}
64 changes: 64 additions & 0 deletions LazyComboBox.WPF/LookupContextImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections;
using System.Threading;

// ReSharper disable UnusedAutoPropertyAccessor.Global

namespace uTILLIty.Controls.WPF.LazyComboBox
{
/// <summary>
/// The context passed to the <see cref="LazyComboBox.LookupAction" /> delegate, when the <see cref="LazyComboBox" />
/// needs to populate the popup-list
/// </summary>
internal class LookupContextImpl : LookupContext
{
internal LookupContextImpl(string input, CancellationToken token, object tag, LazyComboBox cb)
{
SelectedItem = cb.SelectedItem;
Input = input;
CancellationToken = token;
Tag = tag;
}

/// <summary>
/// The currently <see cref="LazyComboBox.SelectedItem">selected item</see> of the <see cref="LazyComboBox" />
/// </summary>
public object SelectedItem { get; private set; }

/// <summary>
/// The user's input into the Textbox field of the <see cref="LazyComboBox" />
/// </summary>
public string Input { get; private set; }

/// <summary>
/// A <see cref="CancellationToken" /> to periodically check for cancellation, in case the user continued
/// to enter data and a new lookup-request needs to be started
/// </summary>
public CancellationToken CancellationToken { get; private set; }

/// <summary>
/// An arbitrary state-object which is passed on subsequent requests to <see cref="LazyComboBox.LookupAction" />, if the
/// <see cref="NextPageRequested" /> property is set to true
/// </summary>
public object Tag { get; set; }

/// <summary>
/// Requests the next page to be loaded, because the user has scrolled to the end of the current list and your
/// <see cref="LazyComboBox.LookupAction" /> has set <see cref="MoreDataAvailable" /> to true on the last run.
/// After loading the next page, you should add the newly loaded page to the end of the <see cref="LoadedList" />
/// </summary>
public bool NextPageRequested { get; internal set; }

/// <summary>
/// The list of records returned by the <see cref="LazyComboBox.LookupAction" /> delegate. The current list is also
/// pre-populated,
/// if <see cref="NextPageRequested" /> is set to true
/// </summary>
public IEnumerable LoadedList { get; set; }

/// <summary>
/// Set by the <see cref="LazyComboBox.LookupAction" /> delegate to indicate that more records are available
/// and can be requested for the current <see cref="Input" />
/// </summary>
public bool MoreDataAvailable { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;

namespace uTILLIty.Controls.WPF.LazyComboBox
namespace uTILLIty.WPF.Demo
{
public enum GenderType
{
Expand Down
1 change: 1 addition & 0 deletions WPF.DemoApplication/WPF.DemoApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="ApplicationHelper.cs" />
<Compile Include="CompanyInfo.cs" />
<Compile Include="EnumItem.cs" />
<Compile Include="GenderType.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down