我有一个程序,其中我有一个立方体,由 GeometryModel3D 表示,我有一个充满纹理的 ListBox,保存在数据库中。每次双击鼠标时,我都会尝试更改立方体的纹理,但它不起作用。请你帮助我好吗?这是源代码:
<ModelVisual3D x:Name="floor">
<ModelVisual3D.Content>
<Model3DGroup>
<DirectionalLight Color="#FFE2E0E0" Direction="-1,-1,-3" >
</DirectionalLight>
<GeometryModel3D x:Name="floorModel">
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="floorGeometry" Positions="{Binding FLoorPoints3D}" TriangleIndices="{Binding FloorPointsIndices}"
TextureCoordinates="0,1 0,0 1,0 1,1 1,1 -0,1 0,-0, 1,0 1,1 -0,1 0,-0 1,0 1,0 1,1 -0,1 0,-0 -0,0 -0,0 1,-0 1,1 0,1 1,-0 1,1 0,1 -0,1"/>
</GeometryModel3D.Geometry>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
public int FloorImagesLoader(string query)
{
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader;
HomeDesigner.Converters converters = new Converters();
List<HomeDesigner.Classes.Floor> floorImageList = new List<Classes.Floor>();
HomeDesigner.Classes.Floor floorClass = new Classes.Floor();
try
{
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
{
floorImageList.Add(new HomeDesigner.Classes.Floor { FloorTextureID = (int)reader[0], Image = converters.ByteArrayToImage(((byte[])reader[1])) });
}
}
}
finally
{
connection.Close();
}
ListBoxImages.ItemsSource = floorImageList;
ID = floorClass.FloorTextureID;
return ID;
}
BitmapImage textureImage = new BitmapImage();
private void SetImageTexture()
{
int parquetIndex = 0;
ListBoxImages.MouseLeftButtonDown += (sender, e) =>
{
if (ListBoxImages.ItemsSource != null)
{
if (buttonParquetClick == true)
{
if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 2)
{
parquetIndex = ListBoxImages.SelectedIndex;
string parquete_Query = "SELECT FloorID, FloorImage FROM HomeDesigner.dbo.Floor where FloorTypeID=3";
textureImage = TexturesLoader(parquete_Query, parquetIndex + 1);
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = textureImage;
floorModel.Material = new DiffuseMaterial(imageBrush);
}
}
else
{
}
}
};
}