Share via


RenderOptions.SetCachingHint(DependencyObject, CachingHint) 方法

定義

設定所指定相依性物件的 CachingHint 附加屬性值。

public:
 static void SetCachingHint(System::Windows::DependencyObject ^ target, System::Windows::Media::CachingHint cachingHint);
public static void SetCachingHint (System.Windows.DependencyObject target, System.Windows.Media.CachingHint cachingHint);
static member SetCachingHint : System.Windows.DependencyObject * System.Windows.Media.CachingHint -> unit
Public Shared Sub SetCachingHint (target As DependencyObject, cachingHint As CachingHint)

參數

target
DependencyObject

要設定 CachingHint 屬性值的相依性物件。

cachingHint
CachingHint

要設定屬性的目標新值。

例外狀況

指定的 targetnull

範例

下列範例示範如何使用 的 DrawingBrush 快取提示選項。

DrawingBrush drawingBrush = new DrawingBrush();
            
// Set the caching hint option for the brush.
RenderOptions.SetCachingHint(drawingBrush, CachingHint.Cache);

// Set the minimum and maximum relative sizes for regenerating the tiled brush.
// The tiled brush will be regenerated and re-cached when its size is
// 0.5x or 2x of the current cached size.
RenderOptions.SetCacheInvalidationThresholdMinimum(drawingBrush, 0.5);
RenderOptions.SetCacheInvalidationThresholdMaximum(drawingBrush, 2.0);
Dim drawingBrush As New DrawingBrush()

' Set the caching hint option for the brush.
RenderOptions.SetCachingHint(drawingBrush, CachingHint.Cache)

' Set the minimum and maximum relative sizes for regenerating the tiled brush.
' The tiled brush will be regenerated and re-cached when its size is
' 0.5x or 2x of the current cached size.
RenderOptions.SetCacheInvalidationThresholdMinimum(drawingBrush, 0.5)
RenderOptions.SetCacheInvalidationThresholdMaximum(drawingBrush, 2.0)

備註

根據預設,WPF 不會快取 和 VisualBrush 物件的轉譯內容 DrawingBrush 。 在靜態案例中,其中內容和場景中筆刷的使用都不會變更,而不是快取可提供好處,因為它會節省視訊記憶體。 以非靜態方式使用具有靜態內容的筆刷時,WPF 的預設行為是重新轉譯每一個畫面格的所有筆刷內容,即使內容未變更也一樣。 例如,當靜態 DrawingBrushVisualBrush 對應至旋轉 3D 物件的表面時,就會發生這種情況。 重新轉譯靜態內容可能會對效能造成負面影響。

藉由將 CachingHint 筆刷的附加屬性設定為 Cache ,您可以使用已快取的磚筆刷物件版本來提升效能。

CacheInvalidationThresholdMinimumCacheInvalidationThresholdMaximum 屬性值是相對大小值,決定 TileBrush 何時應該重新產生物件,因為縮放比例變更。 例如,當 屬性設定為 2.0 時 CacheInvalidationThresholdMaximum ,只有當其大小超過目前快取的大小兩倍時, TileBrush 才需要重新產生 的快取。

使用這個方法,在程式碼中設定 CachingHint 附加屬性。

適用於

另請參閱