Cannot load layout in WPF application - wpf

Hello I am using windows presentation foundation and I fail to load the layout that I save but it doesnt load. I use the XmlLayoutSerializer class and the
Deserialize to load the corresponding xml fle. I assume that something is wrong with the xml file. Could you please have a look at it and check if something s wrong?
<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RootPanel Orientation="Horizontal">
<LayoutAnchorablePane DockWidth="400">
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Selection" IsSelected="True" ContentId="Cont1" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Settings" ContentId="Cont2" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Security settings" ContentId="Cont3" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Log" ContentId="Cont4" CanClose="False" />
</LayoutAnchorablePane>
<LayoutDocumentPane>
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Project" IsSelected="True" IsLastFocusedDocument="True" ContentId="Cont5" CanClose="False" LastActivationTimeStamp="05/22/2015 14:35:39" />
<LayoutDocument Title="Layout" ContentId="Cont6" CanClose="False" />
<LayoutDocument Title="Sequences" ContentId="Cont10" CanClose="False" />
<LayoutDocument Title="Locations" ContentId="Cont11" CanClose="False" />
<LayoutDocument Title="Search" ContentId="Cont12" CanClose="False" />
<LayoutDocument Title="Task generator" ContentId="Cont13" CanClose="False" />
<LayoutDocument Title="Task manager" ContentId="Cont14" CanClose="False" />
<LayoutDocument Title="Layout validator" ContentId="Cont15" CanClose="False" />
<LayoutDocument Title="Variables" ContentId="Cont16" CanClose="False" />
</LayoutDocumentPane>
<LayoutAnchorablePane DockWidth="230">
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Delta & selection tool" IsSelected="True" ContentId="Cont7" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Animations" ContentId="Cont8" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Groups" ContentId="Cont9" CanClose="False" />
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Zones" ContentId="Cont10" CanClose="False" />
</LayoutAnchorablePane>
</RootPanel>
<TopSide />
<RightSide />
<LeftSide />
<BottomSide />
<FloatingWindows />
<Hidden />
</LayoutRoot>
This is the code that I use to save and load the layout (check the comments //saving layout and //loading layout).
private void RestoreWindow()
{
try
{
if (Properties.Settings.Default.WindowHeight == 0 || Properties.Settings.Default.WindowWidth == 0)
{
return;
}
}
catch(Exception e)
{
Debugger.Break();
throw;
}
Height = Properties.Settings.Default.WindowHeight;
Width = Properties.Settings.Default.WindowWidth;
Left = Properties.Settings.Default.WindowLeft;
Top = Properties.Settings.Default.WindowTop;
WindowState = (WindowState)Properties.Settings.Default.WindowState;
// loading the layout
using (var reader = new StreamReader("layoutfile.xml"))
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);
layoutSerializer.Deserialize(reader);
}
}
private void SaveWindow()
{
Properties.Settings.Default.WindowWidth = Width;
Properties.Settings.Default.WindowHeight = Height;
Properties.Settings.Default.WindowLeft = Left;
Properties.Settings.Default.WindowTop = Top;
Properties.Settings.Default.WindowState = (int)WindowState;
// ensure that your settings are written to the disk
Properties.Settings.Default.Save();
// saving the layout
using (var writer = new StreamWriter("layoutfile.xml"))
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);
layoutSerializer.Serialize(writer);
}
}

Related

WPF controls not showing even make it visible

I encounter a problem that I am not sure how to fix. I have "AddAccount" (Button), "AccountsTextBlock" and a ListBox on the main window. If not user is added, the list box will be hidden, once user is added, it will show the ListBox, AddAccount and AccountsTextBlock on the same screen, but AddAccount and AccountsTextBlock will be at different positions from when there's no user. The problem is that AddAccount and AccountsTextBlock didn't show, but a dotted rectangle shows.
<Grid>
<Canvas>
<TextBlock x:Name="AddAccountTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Height="60" Width="369" Text="Add account to allow for simple access to your company resources
" SnapsToDevicePixels="True" Canvas.Left="38" Canvas.Top="313"/>
<Button x:Name="AddAccount" Content="Add Account" Canvas.Left="145" Canvas.Top="333" HorizontalAlignment="Left" VerticalAlignment="Top" Width="140" RenderTransformOrigin="0.466,0.977" IsCancel="True" Height="40" Foreground="White" Background="Blue" Click="OnAddAccount"/>
<TextBlock x:Name="AccountsTextBlock" Canvas.Left="176" TextWrapping="Wrap" Text="Accounts" Canvas.Top="10" Height="33" Width="68" FontSize="16" FontFamily="Tahoma"/>
</Canvas>
<ListBox x:Name="accounts" HorizontalAlignment="Left" Height="237" VerticalAlignment="Top" Width="444" SelectionChanged="ListBox_SelectionChanged" Background="White" BorderBrush="White" Margin="0,47,0,0" RenderTransformOrigin="0.5,0.5">
<ListBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="0.384"/>
<RotateTransform/>
<TranslateTransform X="-0.794"/>
</TransformGroup>
</ListBox.RenderTransform>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Height" Value="100"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="_Border" BorderBrush="Gray" BorderThickness="0.5"
Padding="2"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="_Border" Property="Background" Value="LightSkyBlue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" Width="100" Source="{Binding Path=imagePath}" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Text="{Binding Path=userInfo}"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
public MainWindow()
{
InitializeComponent();
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(authenticatorRegistryKey))
{
Object valueStr = Registry.GetValue(authenticatorRegistryKey, addedUsersRegistryValueName, null);
if (valueStr == null)
{
//no users added yet, hide list box and move add button
accounts.Visibility = Visibility.Collapsed;
AccountsTextBlock.Visibility = Visibility.Collapsed;
Canvas.SetLeft(AddAccountTextBlock, (Application.Current.MainWindow.Width - AddAccountTextBlock.Width) / 2);
Canvas.SetTop(AddAccountTextBlock, (Application.Current.MainWindow.Height - AddAccountTextBlock.Height) / 2 - AddAccount.Height + 10);
Canvas.SetLeft(AddAccount, (Application.Current.MainWindow.Width - AddAccount.Width) / 2);
Canvas.SetTop(AddAccount, (Application.Current.MainWindow.Height - AddAccount.Height) / 2);
}
else
{
//show the added user
List<UserInfo> items = new List<UserInfo>();
items.Add(new UserInfo()
{
userInfo = "abcdefg",
imagePath = ""
});
accounts.ItemsSource = items;
AccountsTextBlock.Visibility = Visibility.Visible;
accounts.Visibility = Visibility.Visible;
}
}
}
private void OnAddAccount(object sender, RoutedEventArgs e)
{
SignInUrlWindow signInUrlWindow = new SignInUrlWindow();
signInUrlWindow.Left = Application.Current.MainWindow.Left;
signInUrlWindow.Top = Application.Current.MainWindow.Top;
signInUrlWindow.Width = Application.Current.MainWindow.Width;
signInUrlWindow.Height = Application.Current.MainWindow.Height;
signInUrlWindow.ShowDialog();
List<UserInfo> items = new List<UserInfo>();
items.Add(new UserInfo()
{
userInfo = "abcdefg",
imagePath = ""
});
accounts.ItemsSource = items;
accounts.Visibility = Visibility.Visible;
AddAccount.Visibility = Visibility.Visible;
AccountsTextBlock.Visibility = Visibility.Visible;
}

Fixed Wrap panel wpf

i am working on wpf window that show list of items next each other with wrapping, i have tried to use WrapPanel in this way:
<Grid>
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Items>
<Button Content="01" Height="30" Width="70"/>
<Button Content="02" Height="35" Width="72"/>
<Button Content="03" Height="20" Width="74"/>
<Button Content="04" Height="25" Width="76"/>
<Button Content="05" Height="18" Width="78"/>
<Button Content="06" Height="50" Width="70"/>
<Button Content="07" Height="40" Width="72"/>
<Button Content="08" Height="55" Width="74"/>
<Button Content="09" Height="45" Width="76"/>
<Button Content="10" Height="25" Width="78"/>
<Button Content="11" Height="20" Width="80"/>
<Button Content="12" Height="30" Width="70"/>
<Button Content="13" Height="45" Width="72"/>
<Button Content="14" Height="30" Width="74"/>
<Button Content="15" Height="20" Width="76"/>
<Button Content="16" Height="25" Width="78"/>
<Button Content="17" Height="35" Width="80"/>
<Button Content="18" Height="50" Width="70"/>
<Button Content="19" Height="55" Width="72"/>
<Button Content="20" Height="45" Width="74"/>
<Button Content="21" Height="20" Width="76"/>
<Button Content="22" Height="60" Width="78"/>
<Button Content="23" Height="20" Width="80"/>
<Button Content="24" Height="25" Width="70"/>
<Button Content="25" Height="30" Width="72"/>
</ItemsControl.Items>
</ItemsControl>
</Grid>
and this is the result:
Actually this result is unsatisfactory for me because if you imagine the WrapPanel as grid(rows and columns) you will find that there is no columns, but there are fixed size rows. i need to make WarpPanel or some control else without columns too, look at this imaginary image:
notice that there is no rows and no columns. this is what i wanna make.
anybody have ideas to solve this issue?
You could write your own custom Panel class. There are some tutorials on the web, simply google "wpf custom panel".
It boils down to overriding the MeasureOverride and ArrangeOverride methods.
public class CustomPanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
Size panelDesiredSize = new Size();
foreach (UIElement child in InternalChildren)
{
child.Measure(availableSize);
// Use child.DesiredSize, availableSize.Width and the positions
// and sizes of the previous children to calculate the position of
// the current child. Then determine the resulting Panel height.
panelDesiredSize = ...
}
return panelDesiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
foreach (UIElement child in InternalChildren)
{
// Arrange each child according to the position calculations
// done in MeasureOverride
Point position = ...
child.Arrange(new Rect(position, child.DesiredSize));
}
return finalSize;
}
}
UPDATE: The following simple custom Panel might more or less do what you want.
public class PackPanel : Panel
{
protected override Size MeasureOverride(Size availableSize)
{
foreach (UIElement child in InternalChildren)
{
child.Measure(availableSize);
}
var positions = new Point[InternalChildren.Count];
var desiredHeight = ArrangeChildren(positions, availableSize.Width);
return new Size(availableSize.Width, desiredHeight);
}
protected override Size ArrangeOverride(Size finalSize)
{
var positions = new Point[InternalChildren.Count];
ArrangeChildren(positions, finalSize.Width);
for (int i = 0; i < InternalChildren.Count; i++)
{
var child = InternalChildren[i];
child.Arrange(new Rect(positions[i], child.DesiredSize));
}
return finalSize;
}
private double ArrangeChildren(Point[] positions, double availableWidth)
{
var lastRowStartIndex = -1;
var lastRowEndIndex = 0;
var currentWidth = 0d;
var desiredHeight = 0d;
for (int childIndex = 0; childIndex < InternalChildren.Count; childIndex++)
{
var child = InternalChildren[childIndex];
var x = 0d;
var y = 0d;
if (currentWidth == 0d || currentWidth + child.DesiredSize.Width <= availableWidth)
{
x = currentWidth;
currentWidth += child.DesiredSize.Width;
}
else
{
currentWidth = child.DesiredSize.Width;
lastRowStartIndex = lastRowEndIndex;
lastRowEndIndex = childIndex;
}
if (lastRowStartIndex >= 0)
{
int i = lastRowStartIndex;
while (i < lastRowEndIndex - 1 && positions[i + 1].X < x)
{
i++;
}
while (i < lastRowEndIndex && positions[i].X < x + child.DesiredSize.Width)
{
y = Math.Max(y, positions[i].Y + InternalChildren[i].DesiredSize.Height);
i++;
}
}
positions[childIndex] = new Point(x, y);
desiredHeight = Math.Max(desiredHeight, y + child.DesiredSize.Height);
}
return desiredHeight;
}
}
You Can Either use Canvas:
Or Use Grid and set the Margin of each Buttons according to requirenment
<Canvas >
<Button Content="s" Width="50" Canvas.Left="17" Canvas.Top="20" />
<Button Canvas.Left="73" Canvas.Top="32" Content="s" Width="60" Height="42" />
<Button Canvas.Left="139" Canvas.Top="10" Content="s" Height="42" Width="60" />
</Canvas>
<Grid >
<Button Content="01" Height="30" Width="70" Margin="20,12,414,268" />
<Button Content="02" Height="35" Width="72" Margin="426,148,6,128" />
<Button Content="03" Height="20" Width="74" Margin="190,122,240,170" />
<Button Content="04" Height="25" Width="76" Margin="386,26,40,260" />
<Button Content="05" Height="18" Width="78" Margin="376,202,48,92" />
<Button Content="06" Height="50" Width="70" Margin="385,64,48,196" />
<Button Content="07" Height="40" Width="72" Margin="162,202,269,68" />
<Button Content="08" Height="55" Width="74" Margin="20,154,408,102" />
<Button Content="09" Height="45" Width="76" Margin="21,95,406,171" />
<Button Content="10" Height="25" Width="78" Margin="44,47,382,239" />
<Button Content="11" Height="20" Width="80" Margin="386,120,38,170" />
<Button Content="12" Height="30" Width="70" Margin="95,13,338,268" />
<Button Content="13" Height="45" Width="72" Margin="290,6,140,260" />
<Button Content="14" Height="30" Width="74" Margin="210,38,220,244" />
<Button Content="15" Height="20" Width="76" Margin="128,48,299,242" />
<Button Content="16" Height="25" Width="78" Margin="265,189,160,97" />
<Button Content="17" Height="35" Width="80" Margin="176,154,246,122" />
<Button Content="18" Height="50" Width="70" Margin="100,146,333,116" />
<Button Content="19" Height="55" Width="72" Margin="270,121,160,135" />
<Button Content="20" Height="45" Width="74" Margin="348,148,81,118" />
<Button Content="21" Height="20" Width="76" Margin="94,78,332,212" />
<Button Content="22" Height="60" Width="78" Margin="270,60,155,192" />
<Button Content="23" Height="20" Width="80" Margin="176,74,247,216" />
<Button Content="24" Height="25" Width="70" Margin="194,95,238,191" />
<Button Content="25" Height="30" Width="72" Margin="117,104,314,177" />
</Grid>

Implementing Drag and Swapping items in windows Phone

I am new to windows phone.My problem is the following:
I have a grid of items which are buttons. I want to implement drag and swap feature for the buttons.How to do this in WP7 platform.
Here is the solution! xaml looks like this
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<toolkit:WrapPanel Height="510" HorizontalAlignment="Left" Margin="18,56,0,0" Name="wrapPanel1" VerticalAlignment="Top" Width="411">
<Button Content="1" Height="124" Name="button2" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="2" Height="124" Name="button3" Width="134" >
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="3" Height="124" Name="button4" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="4" Height="124" Name="button5" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="5" Height="124" Name="button6" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="6" Height="124" Name="button7" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="7" Height="124" Name="button8" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="8" Height="124" Name="button9" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="9" Height="124" Name="button10" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="10" Height="124" Name="button11" MouseLeftButtonDown="mouseDown" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="11" Height="124" Name="button12" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
<Button Content="12" Height="124" Name="button13" Width="134">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" />
</toolkit:GestureService.GestureListener>
</Button>
</toolkit:WrapPanel>
</Grid>
Now the code behind C#
TranslateTransform translateTransform;
PointCollection points = new System.Windows.Media.PointCollection();
Button firstObject;
private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
{
translateTransform = new TranslateTransform();
firstObject = sender as Button;
var transform1 = firstObject.TransformToVisual(wrapPanel1);
Point absolutePosition1 = transform1.Transform(new Point(0, 0));
}
private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
var moveablebutton = sender as Button;
moveablebutton.RenderTransform = translateTransform;
translateTransform.X += e.HorizontalChange;
translateTransform.Y += e.VerticalChange;
}
private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
var lastObject = sender as Button;
Button b=new Button();
int count = wrapPanel1.Children.Count;
int index = wrapPanel1.Children.IndexOf(lastObject);
var transform2 = lastObject.TransformToVisual(wrapPanel1);
Point absolutePositon2 = transform2.Transform(new Point(0, 0));
Point P1;
Point P2 ;
Point P3 ;
Point P4 ;
P1 = e.GetPosition(wrapPanel1);
P2 = new Point(P1.X+134, P1.Y+124);
Button swapitem=null;
foreach (UIElement ctrl in wrapPanel1.Children)
{
int index2;
var transform3 = ctrl.TransformToVisual(wrapPanel1);
Point comparePos = transform3.Transform(new Point(0, 0));
swapitem = ctrl as Button;
index2 = wrapPanel1.Children.IndexOf(swapitem);
if (index != index2)
{
P3 = new Point(comparePos.X, comparePos.Y);
P4 = new Point(comparePos.X + 158, comparePos.Y+170);
if (!(P2.Y < P3.Y || P1.Y > P4.Y || P2.X < P3.X || P1.X > P4.X))
{
swapitem = ctrl as Button;
index2 = wrapPanel1.Children.IndexOf(swapitem);
b = lastObject as Button;
b.RenderTransform = translateTransform;
translateTransform.X -= e.HorizontalChange;
translateTransform.Y -= e.VerticalChange;
wrapPanel1.Children.Remove(lastObject);
wrapPanel1.Children.Remove(swapitem);
// wrapPanel1.Children.RemoveAt(index2);
if (index < index2)
{
wrapPanel1.Children.Insert(index, swapitem);
wrapPanel1.Children.Insert(index2, b);
}
else
{
wrapPanel1.Children.Insert(index2, b);
wrapPanel1.Children.Insert(index, swapitem);
}
break;
}}
}
}

Flex Mobile Project, insert multiple Image object in array

I have indexed Image, like these:
<s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
<s:Image id="imgListaTaskAnalysis2" left="20" top="360" width="200" height="200"/>
And so on..
I want to put them in an array, so:
public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1,imgListaTaskAnalysis2);
But I can't give them a source:
for(var i:Number=0;i<=arrayImg.length;i++)
arrayImg[i].source = cuboImmagini.path;
In this way doesn't work, doesn't give them any source..There is a way to do this?
It is the interested part of my project:
public var arrayImg:Array = new Array(imgListaTaskAnalysis0,imgListaTaskAnalysis1);
/* DICHIARAZIONE IMMAGINI */
public var cuboImmagini:Object = {path:"../assets/cuboImmagini.png"};
public var exit:Object = {path:"../assets/exit.png"};
public var home:Object = {path:"../assets/home.png"};
/* FINE DICHIARAZIONE IMMAGINI */
/* FUNZIONI */
// cambiaPagina
public function cambiaPagina(prossimaPagina:String):void
{
currentState = prossimaPagina;
}
// chiudiApplicazione
protected function chiudiApplicazione(event:MouseEvent):void
{
NativeApplication.nativeApplication.exit();
}
public function carica():void
{
arrayImg[0].source = cuboImmagini.path;
arrayImg[1].source = home.path;
cambiaPagina("HomePage");
}
/* FINE FUNZIONI */
]]>
</fx:Script>
<s:states>
<s:State name="PaginaPresentazione"/>
<s:State name="HomePage"/>
<s:State name="ListaTaskAnalysis"/>
<s:State name="ScegliAzioneTaskAnalysis"/>
</s:states>
<fx:Declarations>
</fx:Declarations>
<!-- =================================== MXML =================================== -->
<!-- =================================== PaginaPresentazione =================================== -->
<s:Group id="gruppoPaginaPresentazione" includeIn="PaginaPresentazione" left="0" right="0" top="0" bottom="0"
horizontalCenter="0" verticalCenter="0">
<s:Button id="btnPresentazione" right="10" bottom="10" label="INIZIA"
click="carica()"/>
</s:Group>
<!-- =================================== HomePage =================================== -->
<s:Group id="gruppoHomePage" includeIn="HomePage,PaginaPresentazione" left="0" right="0" top="0"
bottom="0" horizontalCenter="0" verticalCenter="0">
<s:Button id="btnVaiTaskAnalysis" includeIn="HomePage" width="600" height="90"
label="TASK ANALYSIS" click="cambiaPagina('ListaTaskAnalysis')" fontSize="50"
horizontalCenter="0" verticalCenter="80"/>
<s:Button id="btnVaiStorieSociali" includeIn="HomePage" width="600" height="90"
label="STORIE SOCIALI" fontSize="50" horizontalCenter="0" verticalCenter="-80"/>
</s:Group>
<!-- =================================== /HomePage =================================== -->
<s:Group id="gruppoListaTaskAnalysis" includeIn="ListaTaskAnalysis" left="0" right="0" top="0" bottom="0"
horizontalCenter="0" verticalCenter="0">
<s:Group id="gruppoBottoniListaTaskAnalyis" left="0" right="0" top="0" height="90"
horizontalCenter="0">
<s:Button id="btnExitListaTaskAnalysis" right="10" top="5" width="80" height="80"
icon="assets/exit.png" click="chiudiApplicazione(event)"/>
<s:Button id="btnHomeListaTaskAnalysis" right="100" top="5" width="80" height="80"
icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
</s:Group>
<s:Image id="imgListaTaskAnalysis0" left="20" top="110" width="200" height="200"
source="assets/cuboImmagini.png"/>
<s:Image id="imgListaTaskAnalysis1" left="20" top="360" width="200" height="200"/>
<s:Button id="btnSegreto1" left="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(1)"/>
<s:Button id="btnSegreto2" right="10" bottom="10" width="90" height="90" alpha="0.1" click="combinazioneSegreta(2)"/>
</s:Group>
<s:Group id="gruppoListaTaskAnalysis0" includeIn="ScegliAzioneTaskAnalysis" left="0" right="0"
top="0" bottom="0" horizontalCenter="0" verticalCenter="0">
<s:Group id="gruppoBottoniListaTaskAnalyis0" left="0" right="0" top="0" height="90"
horizontalCenter="0">
<s:Button id="btnExitScegliAzioneTaskAnalysis0" right="10" top="5" width="80" height="80"
icon="assets/exit.png" click="chiudiApplicazione(event)"/>
<s:Button id="btnHomeScegliAzioneTaskAnalisys" right="100" top="5" width="80" height="80"
icon="assets/home.png" click = "cambiaPagina('HomePage')"/>
</s:Group>
</s:Group>
<!-- =================================== /HomePage =================================== -->
Thanks in advance..
I solved the problem.. I put the images in the array when they are created:
<s:Image id="img" creationComplete = "loadImage(event,this.img,0) />
---------------------------------------------------------------------
public function loadImage(e:FlexEvent,img:Image,num:Number):void
{
array[num] = img;
}
Thanks anyway..

WPF: LineBreak enable/disable dynamically

i would like to make the LineBreak element inside of that TextBlock controllable by the user in preferences to Enable/Disable it being there
<TextBlock Style="{StaticResource TextBlockStyle}" Width="130">
<TextBlock.Inlines>
<Run Text="{Binding Path=Name}" FontWeight="Bold" Foreground="#FF2A4D9E" />
<Run Text="{Binding Path=Price}" FontWeight="Bold" />
<LineBreak />
<Run Text="{Binding Path=Quantity}" Foreground="#99000000" />
</TextBlock.Inlines>
</TextBlock>
I don't believe there is any way in a FlowDocument to make a LineBreak not really break except to take it out. Your choices are to switch to using WPF layout or to use an attached property to switch between a LineBreak and an empty Run.
Using WPF layout
You may consider using WPF layout instead. Something like this:
<DataTemplate x:Key="Layout1">
<DockPanel>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="#FF2A4D9E" />
<TextBlock Text="{Binding Price}" FontWeight="Bold" />
<TextBlock Text="{Binding Quantity}" Foreground="#99000000" />
</DockPanel>
</DataTemplate>
<DataTemplate x:Key="Layout2">
<DockPanel>
<DockPanel DockPanel.Dock="Top">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="#FF2A4D9E" />
<TextBlock Text="{Binding Price}" FontWeight="Bold" />
</DockPanel>
<TextBlock Text="{Binding Quantity}" Foreground="#99000000" />
</DockPanel>
</DataTemplate>
Now you can easily switch between layouts just by switching DataTemplates.
Automatically removing LineBreaks using bindings
If you want to "hide" the LineBreak via a binding you can do it with an attached "BecomeLineBreak" property that, when applied to an empty Run and set true, removes it and replaces it with a LineBreak.
Like magic you now have the ability to write:
<Run my:LineBreakSwitcher.BecomeLineBreak="{Binding SomeCondition}" />
And your Run will turn into a LineBreak any time the SomeCondition property is true.
Here is the code:
public class LineBreakSwitcher : DependencyObject
{
public static bool GetBecomeLineBreak(DependencyObject obj) { return (bool)obj.GetValue(BecomeLineBreakProperty); }
public static void SetBecomeLineBreak(DependencyObject obj, bool value) { obj.SetValue(BecomeLineBreakProperty, value); }
public static readonly DependencyProperty BecomeLineBreakProperty = DependencyProperty.RegisterAttached("BecomeLineBreak", typeof(bool), typeof(LineBreakSwitcher), new PropertyMetadata
{
PropertyChangedCallback = (obj, e) =>
{
var oldElement = (Inline)obj;
var newElement = (bool)e.NewValue ? (Inline)new LineBreak() : new Run();
newElement.SetBinding(BecomeLineBreakProperty, oldElement.GetBindingExpression(BecomeLineBreakProperty).ParentBindingBase);
var parent = (Paragraph)oldElement.Parent;
parent.Inlines.InsertBefore(oldElement, newElement);
parent.Inlines.Remove(oldElement);
}
});
How it works: When BecomeLineBreak becomes true on a Run, a new LineBreak is created, the BecomeLineBreak binding is copied across, the LineBreak is inserted before the Run, then the Run is removed. When BecomeLineBreak become false, a new Run is created and the whole process happens in reverse.
This is what you want (100% XAML):
<TextBlock Text="{Binding Text, ElementName=MyContainer}"
FontWeight="Bold" FontSize="14" Name="TextBlockA" />
<TextBlock Name="TextBlockB">
<TextBlock.Style>
<Style>
<Setter Property="TextBlock.Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text.Length,
ElementName=TextBlockC}" Value="0">
<Setter Property="TextBlock.Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<LineBreak />
</TextBlock>
<TextBlock Text="{Binding SubText, ElementName=MyContainer}"
FontWeight="Normal" FontSize="12" Name="TextBlockC" />

Resources