fixed #155
This commit is contained in:
1 parent
16b155f579
commit
14fff8cf16
2 files changed
+35
-11
No files matched your search
@@ -44,6 +44,8 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private bool _isLoaded;
|
private bool _isLoaded;
|
||||||
|
|
||||||
|
private bool _updateItems;
|
||||||
|
|
||||||
public Rate()
|
public Rate()
|
||||||
{
|
{
|
||||||
AddHandler(RateItem.SelectedChangedEvent, new RoutedEventHandler(RateItemSelectedChanged));
|
AddHandler(RateItem.SelectedChangedEvent, new RoutedEventHandler(RateItemSelectedChanged));
|
||||||
@@ -52,8 +54,15 @@ namespace HandyControl.Controls
|
|||||||
Loaded += (s, e) =>
|
Loaded += (s, e) =>
|
||||||
{
|
{
|
||||||
if (DesignerHelper.IsInDesignMode) return;
|
if (DesignerHelper.IsInDesignMode) return;
|
||||||
|
|
||||||
|
_updateItems = false;
|
||||||
|
OnApplyTemplateInternal();
|
||||||
|
_updateItems = true;
|
||||||
|
UpdateItems();
|
||||||
|
|
||||||
if (_isLoaded) return;
|
if (_isLoaded) return;
|
||||||
_isLoaded = true;
|
_isLoaded = true;
|
||||||
|
|
||||||
if (Value <= 0)
|
if (Value <= 0)
|
||||||
{
|
{
|
||||||
if (DefaultValue > 0)
|
if (DefaultValue > 0)
|
||||||
@@ -164,21 +173,30 @@ namespace HandyControl.Controls
|
|||||||
return new RateItem();
|
return new RateItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnApplyTemplate()
|
private void OnApplyTemplateInternal()
|
||||||
{
|
|
||||||
if (!_isLoaded)
|
|
||||||
{
|
{
|
||||||
Items.Clear();
|
Items.Clear();
|
||||||
|
|
||||||
for (var i = 1; i <= Count; i++)
|
for (var i = 1; i <= Count; i++)
|
||||||
{
|
{
|
||||||
Items.Add(new RateItem
|
var item = new RateItem
|
||||||
{
|
{
|
||||||
Index = i
|
Index = i
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
if (!_isLoaded)
|
||||||
|
{
|
||||||
|
_updateItems = true;
|
||||||
|
OnApplyTemplateInternal();
|
||||||
|
_updateItems = false;
|
||||||
|
}
|
||||||
|
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +209,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
protected override void UpdateItems()
|
protected override void UpdateItems()
|
||||||
{
|
{
|
||||||
if (!_isLoaded) return;
|
if (!_isLoaded || !_updateItems) return;
|
||||||
var count = (int) Value;
|
var count = (int) Value;
|
||||||
|
|
||||||
for (var i = 0; i < count; i++)
|
for (var i = 0; i < count; i++)
|
||||||
|
|||||||
@@ -46,7 +46,13 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
public RateItem()
|
public RateItem()
|
||||||
{
|
{
|
||||||
Loaded += (s, e) => _isLoaded = true;
|
Loaded += (s, e) =>
|
||||||
|
{
|
||||||
|
if (_isLoaded) return;
|
||||||
|
_isLoaded = true;
|
||||||
|
|
||||||
|
OnApplyTemplate();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AllowClear
|
public bool AllowClear
|
||||||
@@ -87,7 +93,7 @@ namespace HandyControl.Controls
|
|||||||
if (_isHalf == value) return;
|
if (_isHalf == value) return;
|
||||||
_isHalf = value;
|
_isHalf = value;
|
||||||
if (_icon == null) return;
|
if (_icon == null) return;
|
||||||
_icon.Width = value ? ActualWidth / 2 : ActualWidth;
|
_icon.Width = value ? Width / 2 : Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +140,7 @@ namespace HandyControl.Controls
|
|||||||
if (IsReadOnly) return;
|
if (IsReadOnly) return;
|
||||||
if (!AllowHalf) return;
|
if (!AllowHalf) return;
|
||||||
var p = e.GetPosition(this);
|
var p = e.GetPosition(this);
|
||||||
IsHalf = p.X < ActualWidth / 2;
|
IsHalf = p.X < Width / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
@@ -147,7 +153,7 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
if (_icon == null) return;
|
if (_icon == null) return;
|
||||||
_icon.Show(IsSelected);
|
_icon.Show(IsSelected);
|
||||||
_icon.Width = IsHalf ? ActualWidth / 2 : ActualWidth;
|
_icon.Width = IsHalf ? Width / 2 : Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +208,7 @@ namespace HandyControl.Controls
|
|||||||
if (AllowHalf)
|
if (AllowHalf)
|
||||||
{
|
{
|
||||||
var p = e.GetPosition(this);
|
var p = e.GetPosition(this);
|
||||||
IsHalf = p.X < ActualWidth / 2;
|
IsHalf = p.X < Width / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user