저는 WPF를 처음 사용합니다.WPF에서 다중 이미지 자동 조절 배경을 구현하는 방법은 무엇입니까? Android의 9 가지 패치와 비슷합니까?
두 개의 "창", 마스터 창 및 세부 창으로 분할 된 앱이 있습니다. 마스터 창은 높이가 좁고 왼쪽으로 정렬되어 있습니다. 세부 정보 창은 넓으며 대부분의 앱 영역을 차지하며 오른쪽 정렬됩니다.
여기 내 목표는 각 창의 크기가 큰 이미지 배경을 구현하는 것입니다. 이 개념은 Android의 Nine Patch () 메커니즘과 유사합니다. 사실이 WPF 앱은 동일한 앱의 Android 버전에서 사용되는 것과 동일한 소스 PNG를 사용합니다. 보시다시피이 앱은 교차 플랫폼 앱입니다. 두 플랫폼 모두에서 비즈니스 객체와 로직을 공유하지만 UI 구현은 앱이 서로 다른 부분입니다.
Nine Patch 문서를 읽을 때 은을 무시합니다. 어떤 종류의보기에도 구현할 수 있습니다. 앱의 배경을 비롯하여 iOS에서 이미 작동하는 개념이 있습니다. 이제 WPF 및 Silverlight로 개념을 포팅해야합니다.
각 창의 루트 컨테이너는 System.Windows.Controls입니다. 그리드. 내가 말할 수있는 가장 좋은 방법은 그리드를 3x3 구조로 분할 한 다음 WPF 속성 바인딩을 통해 각각의 적절한 그리드 섹션에 9 개의 패치 이미지의 각 부분을 적용하는 것입니다. ImageBrush. 그러나 WPF 또는 그 바인딩 기능에 그리드를 만드는 데 완전히 익숙하지 않습니다. 그리고 창 크기 조정이 어떻게 처리 될까요?
이것에 대한 조언은 크게 감사하겠습니다. 감사.
편집 :이 경우에는 XAML을 사용할 수 없다는 점도 언급해야합니다. 이것은 모두 프로그래밍 방식으로 이루어져야합니다.
편집 : loxxy의 충고를 잘 보여주고 다음 단계에 대한 추가 안내를 원합니다. 여기에 지금까지 내 구현 결과이다 (I 등등 읽어 보시기 바랍니다 아래의 질문이) :
NOW
NinePatchImage npi = new NinePatchImage([some params]);
Grid backgroundGrid = new Grid();
backgroundGrid.ColumnDefinitions.Clear();
backgroundGrid.RowDefinitions.Clear();
backgroundGrid.ColumnDefinitions.Add(
// first column
new ColumnDefinition()
{
Width = new GridLength(1, GridUnitType.Auto),
});
backgroundGrid.ColumnDefinitions.Add(
// second column
new ColumnDefinition()
{
Width = new GridLength(1, GridUnitType.Star)
});
backgroundGrid.ColumnDefinitions.Add(
// third column
new ColumnDefinition()
{
Width = new GridLength(1, GridUnitType.Auto)
});
backgroundGrid.RowDefinitions.Add(
// first row
new RowDefinition()
{
Height = new GridLength(1, GridUnitType.Auto),
});
backgroundGrid.RowDefinitions.Add(
// second row
new RowDefinition()
{
Height = new GridLength(1, GridUnitType.Star)
});
backgroundGrid.RowDefinitions.Add(
// third row
new RowDefinition()
{
Height = new GridLength(1, GridUnitType.Auto)
});
var imageTopLeft = new Image() { Source = (npi.TopLeft != null) ? npi.TopLeft : null, Stretch = Stretch.None };
var imageTopCenter = new Image() { Source = (npi.TopCenter != null) ? npi.TopCenter : null, Stretch = Stretch.None };
var imageTopRight = new Image() { Source = (npi.TopRight != null) ? npi.TopRight : null, Stretch = Stretch.None };
var imageMiddleLeft = new Image() { Source = (npi.MiddleLeft != null) ? npi.MiddleLeft : null, Stretch = Stretch.None };
var imageMiddleCenter = new Image() { Source = (npi.MiddleCenter != null) ? npi.MiddleCenter : null, Stretch = Stretch.None };
var imageMiddleRight = new Image() { Source = (npi.MiddleRight != null) ? npi.MiddleRight : null, Stretch = Stretch.None };
var imageBottomLeft = new Image() { Source = (npi.BottomLeft != null) ? npi.BottomLeft : null, Stretch = Stretch.None };
var imageBottomCenter = new Image() { Source = (npi.BottomCenter != null) ? npi.BottomCenter : null, Stretch = Stretch.None };
var imageBottomRight = new Image() { Source = (npi.BottomRight != null) ? npi.BottomRight : null, Stretch = Stretch.None };
backgroundGrid.Children.Add(imageTopLeft); Grid.SetColumn(imageTopLeft, 0); Grid.SetRow(imageTopLeft, 0);
backgroundGrid.Children.Add(imageTopCenter); Grid.SetColumn(imageTopCenter, 1); Grid.SetRow(imageTopCenter, 0);
backgroundGrid.Children.Add(imageTopRight); Grid.SetColumn(imageTopRight, 2); Grid.SetRow(imageTopRight, 0);
backgroundGrid.Children.Add(imageMiddleLeft); Grid.SetColumn(imageMiddleLeft, 0); Grid.SetRow(imageMiddleLeft, 1);
backgroundGrid.Children.Add(imageMiddleCenter); Grid.SetColumn(imageMiddleCenter, 1); Grid.SetRow(imageMiddleCenter, 1);
backgroundGrid.Children.Add(imageMiddleRight); Grid.SetColumn(imageMiddleRight, 2); Grid.SetRow(imageMiddleRight, 1);
backgroundGrid.Children.Add(imageBottomLeft); Grid.SetColumn(imageBottomLeft, 0); Grid.SetRow(imageBottomLeft, 2);
backgroundGrid.Children.Add(imageBottomCenter); Grid.SetColumn(imageBottomCenter, 1); Grid.SetRow(imageBottomCenter, 2);
backgroundGrid.Children.Add(imageBottomRight); Grid.SetColumn(imageBottomRight, 2); Grid.SetRow(imageBottomRight, 2);
Grid contentArea = new Grid() { ColumnDefinitions = { new ColumnDefinition() } };
// setup contentArea here blah blah blah
// a containing grid
Grid container = new Grid();
// add the background grid to the containing grid
container.Children.Add(backgroundGrid);
// add the content grid to the background grid's UIElement collection
backgroundGrid.Children.Add(contentArea);
// set the backgroundGrid's column position
Grid.SetColumn(backgroundGrid, 0);
// set the backgroundGrid's row position
Grid.SetRow(backgroundGrid, 0);
// set the content area's column position
Grid.SetColumn(contentArea, 1);
// set the content area's row position
Grid.SetRow(contentArea, 1);
, 나는 상단과 측면 이미지가 올바른 방향으로 늘리거나 타일을 얻을 필요 , x 또는 y. 이미지 WPF 요소에는 여러 옵션이있는 스트레치 속성이 있지만 x 및 y 방향 모두에서 스트레치가 발생하지만 두 치수 중 하나만 스트레칭해야합니다. 또한 필요한 경우 (위의 이미지와 마찬가지로) x 또는 y에서 TILE을 수행 할 수 있어야합니다. image 요소는 이것을 지원하지 않지만 ImageBrush 클래스는 이러한 종류의 것들에 매우 유용 할 수 있습니다. ImageBrush를 Image 요소 나 다른 유형의 요소에 직접 바인딩 할 수 있습니까 ??
로 바인딩의 컨버터를 구현 : – NovaJoe
그냥 나는이 모든 정리 가지고 언급하고 싶었다. 좋은 작품! – NovaJoe