0
Storyboard.Children
을 .AddRange
으로 확장하는 방법이 있습니까? .Add
대신?어쨌든 스토리 보드를 연장하십시오. 어린이?
Storyboard.Children
을 .AddRange
으로 확장하는 방법이 있습니까? .Add
대신?어쨌든 스토리 보드를 연장하십시오. 어린이?
C# extension methods을 사용하면 AddRange 메서드를 제공하는 편리한 방법입니다. 추가 호출을 여러 번 호출하는 것보다 빠르지 않습니다.
여기에 한 가지 예가 나와 있습니다 (nulls 등에 대한 오류 검사를 추가 할 수 있습니다).
는 당신도 할 수있는, 사용하려면sb.Children.AddRange(timelineInst1, timelineInst2);
또는 목록을 전달합니다. timelineInst
sb.Children.AddRange(timelineInsts);
는 IEnuermable<Timeline>
를 구현하는리스트이다.
public static class StoryboardExtensions
{
public static void AddRange(this TimelineCollection timeline, IEnumerable<Timeline> timelines)
{
foreach (Timeline t in timelines)
{
timeline.Add(t);
}
}
public static void AddRange(this TimelineCollection timeline, params Timeline[] timelines)
{
if (timeline == null || timelines.Length == 0) { return; }
foreach (Timeline t in timelines)
{
timeline.Add(t);
}
}
}
우수 감사합니다. – Stan