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